Vue报错记录

820 阅读1分钟

1.Vue props支持多类型的写法,解决 property should be a constructor报错

formVal: {
  // error  The "formVal" property should be a constructor  vue/require-prop-type-constructor
  type: String | Number,
  default: undefined
},

使用 String | Number,有些eslint会报错 error The "formVal" property should be a constructor vue/require-prop-type-constructor(eslint.vuejs.org/rules/requi…)

解决办法:改传数组

formVal: {
  type: [String, Number],
  default: undefined
},

2.[Vue warn]: Extraneous non-props attributes (class) were passed to component but could not be automatically inherited because component renders fragment or text root nodes.

[Vue warn]:额外的非道具属性(类)已传递给组件,但由于组件呈现片段或文本根节点,因此无法自动继承。

报错原因/解决方法

1.就是你有需要传输一个prop属性的数据给子组件,但是你在子组件中忘记用defineProps接收,无意中触发了透传 Attributes,在使用setup语法糖的情况下注意使用defineProps接收props属性数据。

2.该组件中存在多个根节点。(改为一个)