uni-app 使用 uni-ui 库报错

发布于 1周前 作者 htzhanglong 来自 Uni-App

uni-app 使用 uni-ui 库报错

uniapp x 仅仅添加了上述代码就爆粗了

[HBuilder] 12:10:57.071 warning: Expected 4 arguments, but got 3.
[HBuilder] 12:10:57.072 at node_modules/@dcloudio/uni-ui/lib/uni-forms/uni-forms.vue:228:16
[HBuilder] 12:10:57.072   226 | */
[HBuilder] 12:10:57.072   227 | validate(keepitem, callback) {
[HBuilder] 12:10:57.072 > 228 |     return this.checkAll(this.formData, keepitem, callback);
[HBuilder] 12:10:57.072       |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[HBuilder] 12:10:57.072   229 | },
[HBuilder] 12:10:57.072   230 |
[HBuilder] 12:10:57.072   231 | /**
[HBuilder] 12:10:57.073 warning: No overload matches this call.
[HBuilder] 12:10:57.073 Overload 1 of 2, '(searchElement: never, fromIndex?: number | undefined): number', gave the following error.
[HBuilder] 12:10:57.073   Argument of type 'any' is not assignable to parameter of type 'never'.
[HBuilder] 12:10:57.073 Overload 2 of 2, '(searchElement: never, fromIndex?: number | undefined): number', gave the following error.
[HBuilder] 12:10:57.073 at node_modules/@dcloudio/uni-ui/lib/uni-forms/uni-forms.vue:242:23
[HBuilder] 12:10:57.073   240 |                 this.childrens.forEach(item => {
[HBuilder] 12:10:57.073   241 |                     const name = realName(item.name)
[HBuilder] 12:10:57.073 > 242 |                     if (props.indexOf(name) !== -1) {
[HBuilder] 12:10:57.073       |                                       ^^^^
[HBuilder] 12:10:57.074   243 |                         invalidFields = Object.assign({}, invalidFields, {
[HBuilder] 12:10:57.074 warning: Expected 4 arguments, but got 3.
[HBuilder] 12:10:57.074 at node_modules/@dcloudio/uni-ui/lib/uni-forms/uni-forms.vue:248:16
[HBuilder] 12:10:57.074   246 |                     }
[HBuilder] 12:10:57.074   247 |                 });
[HBuilder] 12:10:57.074 > 248 |                 return this.checkAll(invalidFields, [], callback);
[HBuilder] 12:10:57.074       |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[HBuilder] 12:10:57.074   249 |             },
[HBuilder] 12:10:57.075   250 |
[HBuilder] 12:10:57.075   251 | /**
[HBuilder] 12:10:57.075 warning: No overload matches this call.
[HBuilder] 12:10:57.075 Overload 1 of 2, '(searchElement: never, fromIndex?: number | undefined): number', gave the following error.
[HBuilder] 12:10:57.075   Argument of type 'any' is not assignable to parameter of type 'never'.
[HBuilder] 12:10:57.075 Overload 2 of 2, '(searchElement: never, fromIndex?: number | undefined): number', gave the following error.
[HBuilder] 12:10:57.075 at node_modules/@dcloudio/uni-ui/lib/uni-forms/uni-forms.vue:263:24
[HBuilder] 12:10:57.075   261 |                     } else {
[HBuilder] 12:10:57.075   262 |                         const name = realName(item.name)
[HBuilder] 12:10:57.075 > 263 |                         if (props.indexOf(name) !== -1) {
[HBuilder] 12:10:57.075       |                                           ^^^^
[HBuilder] 12:10:57.076   264 |                             item.errMsg = '';
[HBuilder] 12:10:57.076   265 |                         }
[HBuilder] 12:10:57.076   266 |                     }
[HBuilder] 12:10:57.076 warning: No overload matches this call.
[HBuilder] 12:10:57.076 Overload 1 of 2, '(...items: never[]): number', gave the following error.
[HBuilder] 12:10:57.076   Argument of type 'any' is not assignable to parameter of type 'never'.
[HBuilder] 12:10:57.076 Overload 2 of 2, '(...items: never[]): number', gave the following error.
[HBuilder] 12:10:57.076 at node_modules/@dcloudio/uni-ui/lib/uni-forms/uni-forms.vue:303:21
[HBuilder] 12:10:57.076   301 |                     const item = this.childrens.find(v => realName(v.name) === i)
[HBuilder] 12:10:57.077   302 |                     if (item) {
[HBuilder] 12:10:57.077 > 303 |                         childrens.push(item)
[HBuilder] 12:10:57.077       |                                        ^^^^
[HBuilder] 12:10:57.077   304 |                     }
[HBuilder] 12:10:57.077   305 |                 }
[HBuilder] 12:10:57.077   306 |
[HBuilder] 12:10:57.077 warning: Property 'name' does not exist on type 'never'.
[HBuilder] 12:10:57.077 at node_modules/@dcloudio/uni-ui/lib/uni-forms/uni-forms.vue:328:31
[HBuilder] 12:10:57.077   326 |                 for (let i in childrens) {
[HBuilder] 12:10:57.077   327 |                     const child = childrens[i]
[HBuilder] 12:10:57.077 > 328 |                     let name = realName(child.name);
[HBuilder] 12:10:57.078       |                                               ^^^^
[HBuilder] 12:10:57.078   329 |                     const result = await child.onFieldChange(tempFormData[name]);
[HBuilder] 12:10:57.078   330 |                     if (result) {
[HBuilder] 12:10:57.078   331 |                         results.push(result);
[HBuilder] 12:10:57.078 warning: Property 'onFieldChange' does not exist on type 'never'.
[HBuilder] 12:10:57.078 at node_modules/@dcloudio/uni-ui/lib/uni-forms/uni-forms.vue:329:32
[HBuilder] 12:10:57.079   327 |                     const child = childrens[i]
[HBuilder] 12:10:57.079   328 |                     let name = realName(child.name);
[HBuilder] 12:10:57.079 > 329 |                     const result = await child.onFieldChange(tempFormData[name]);
[HBuilder] 12:10:57.079       |                                                ^^^^^^^^^^^^^
[HBuilder] 12:10:57.079   330 |                     if (result) {
[HBuilder] 12:10:57.079   331 |                         results.push(result);
[HBuilder] 12:10:57.079   332 |                         // toast ,modal 只需要执行第一次就可以
[HBuilder] 12:10:57.079 warning: 'tempFormData' is possibly 'null'.
[HBuilder] 12:10:57.079 at node_modules/@dcloudio/uni-ui/lib/uni-forms/uni-forms.vue:329:46
[HBuilder] 12:10:57.079   327 |                     const child = childrens[i]
[HBuilder] 12:10:57.079   328 |                     let name = realName(child.name);
[HBuilder] 12:10:57.080 > 329 |                     const result = await child.onFieldChange(tempFormData[name]);
[HBuilder] 12:10:57.080       |                                                              ^^^^^^^^^^^^
[HBuilder] 12:10:57.080   330 |                     if (result) {
[HBuilder] 12:10:57.080   331 |                         results.push(result);
[HBuilder] 12:10:57.080   332 |                         // toast ,modal 只需要执行第一次就可以
[HBuilder] 12:10:57.080 warning: No overload matches this call.
[HBuilder] 12:10:57.080 Overload 1 of 2, '(...items: never[]): number', gave the following error.
[HBuilder] 12:10:57.080   Argument of type 'any' is not assignable to parameter of type 'never'.
[HBuilder] 12:10:57.080 Overload 2 of 2, '(...items: never[]): number', gave the following error.
[HBuilder] 12:10:57.080 at node_modules/@dcloudio/uni-ui/lib/uni-forms/uni-forms.vue:331:19
[HBuilder] 12:10:57.081   329 |                     const result = await child.onFieldChange(tempFormData[name]);
[HBuilder] 12:10:57.081   330 |                     if (result) {
[HBuilder] 12:10:57.081 > 331 |                         results.push(result);
[HBuilder] 12:10:57.081       |                                      ^^^^^^
[HBuilder] 12:10:57.081   332 |                         // toast ,modal 只需要执行第一次就可以
[HBuilder] 12:10:57.081   333 |                         if (this.errShowType === 'toast' || this.errShowType === 'modal') break;
[HBuilder] 12:10:57.081   334 |                     }
[HBuilder] 12:10:57.081 warning: Type 'null' is not assignable to type 'never[]'.
[HBuilder] 12:10:57.081 at node_modules/@dcloudio/uni-ui/lib/uni-forms/uni-forms.vue:339:31
[HBuilder] 12:10:57.081   337 |
[HBuilder] 12:10:57.081   338 |                 if (Array.isArray(results)) {
[HBuilder] 12:10:57.081 > 339 |                     if (results.length === 0) results = null;
[HBuilder] 12:10:57.082       |                                               ^^^^^^^
[HBuilder] 12:10:57.082   340 |                 }
[HBuilder] 12:10:57.082   341 |                 if (Array.isArray(keepitem)) {
[HBuilder] 12:10:57.082   342 |                     keepitem.forEach(v => {
[HBuilder] 12:10:57.082 warning: 'tempFormData' is possibly 'null'.
[HBuilder] 12:10:57.082 at node_modules/@dcloudio/uni-ui/lib/uni-forms/uni-forms.vue:346:7
[HBuilder] 12:10:57.082   344 |                         let value = getDataValue(v, this.localData)
[HBuilder] 12:10:57.082   345 |                         if (value !== undefined) {
[HBuilder] 12:10:57.082 > 346 |                             tempFormData[vName] = value
[HBuilder] 12:10:57.082       |                             ^^^^^^^^^^^^
[HBuilder] 12:10:57.082   347 |                         }
[HBuilder] 12:10:57.083   348 |                     });
[HBuilder] 12:10:57.083   349 |                 }

1 回复

在使用 uni-app 结合 uni-ui 库时遇到报错问题,通常可能是由于多种原因引起的,包括但不限于版本不兼容、组件使用错误、依赖未正确安装等。以下是一些常见的排查步骤和示例代码,帮助你定位并解决问题。

1. 确认uni-ui库版本与uni-app兼容

首先,确保你使用的uni-ui库版本与uni-app的版本兼容。可以在uni-ui的官方文档或GitHub仓库中查看兼容性信息。

2. 安装uni-ui库

如果尚未安装uni-ui库,可以通过npm或yarn进行安装:

npm install @dcloudio/uni-ui --save
# 或者
yarn add @dcloudio/uni-ui

3. 引入并使用组件

确保你按照uni-ui的文档正确引入了所需的组件。以下是一个简单的示例,展示如何在uni-app中使用uni-ui的u-button组件:

main.js

import Vue from 'vue'
import App from './App'
import '@dcloudio/uni-ui/lib/uni-button/uni-button.scss'

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
    ...App
})
app.$mount()

pages/index/index.vue

<template>
  <view>
    <u-button type="primary" @click="handleClick">点击我</u-button>
  </view>
</template>

<script>
import { Button } from '@dcloudio/uni-ui'

export default {
  components: {
    'u-button': Button
  },
  methods: {
    handleClick() {
      uni.showToast({
        title: '按钮被点击了',
        icon: 'success'
      })
    }
  }
}
</script>

<style>
/* 可以在这里添加自定义样式 */
</style>

4. 检查报错信息

如果仍然遇到报错,请仔细阅读报错信息。报错信息通常会给出具体的错误原因,比如组件未注册、属性名错误等。

5. 清理缓存并重启

有时候,开发工具的缓存可能导致一些问题。尝试清理开发工具缓存并重启,看是否解决问题。

6. 查看官方示例和社区

如果以上步骤仍未解决问题,建议查看uni-ui的官方示例代码,或在社区论坛、GitHub Issues等地方搜索是否有人遇到并解决了相同的问题。

通过上述步骤,你应该能够定位并解决在使用uni-ui库时遇到的报错问题。如果问题依旧存在,请提供具体的报错信息和代码示例,以便进一步分析。

回到顶部