Vue
※前提条件:本文基于 Vue 2.0 创作
[Vue warn]: Property or method "changeSetting" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. †[edit]
代码:
<CustomForm ref="form"
:changeSetting="changeSetting"
:disForm="!canEdit"
:sup_this="this"
:is-add="isAdd"></CustomForm>
- 可能性1:上面的虽有使用,但是其他地方没有定义,此时只需删掉变量即可
- 可能性2:涉及到使用prop父子组件传值时,有可能是子组件的,props里面没有定义changeSetting造成的
- 可能性3:变量被控件绑定使用了,但是在 data 里面没有定义,此时只需在 data 里面添加定义即可
[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "formData" †[edit]
原因:组件内直接修改props的值会报错
props: {
formData: {
type: Object,
default: null,
},
解决方法:
- 在子组件使用该值时需要经过新变量(chooseType)重新传递,这样当这个值变更时,不会造formData的更改
- 在vue2中,直接修改prop是被视作反模式的。由于在新的渲染机制中,每当父组件重新渲染时,子组件都会被覆盖,所以应该把props看做是不可变对象。不能更改 quantity prop使其和父组件同步 , 而是让应该这个组件提交个事件给父组件,可以 watch formData 变量,如果变量发生改变就使用 $emit 事件 ,所以这里压根不需要 prop,直接将props里面的formData删掉即可。
Invalid default value for prop “XX”: Props with type Object/Array must use a factory function to return the default value. †[edit]
//错误写法
props: {
rlist: {
type:Array,
default: [1, 2, 3, 4, 5]
}
}
//正确写法
props: {
rlist: {
type:Array,
default: function() {
return [1, 2, 3, 4, 5]
}
}
}
TypeError: Cannot read properties of undefined (reading ‘split‘) †[edit]
split报错??!!
split 切割对象的字符串,如果为空就有可能报此错误
Cannot read properties of undefined (reading '0') †[edit]
对数组的数据取值时,数组的变量没值时,发生这个问题
regeneratorRuntime is not defined †[edit]
async/await的使用不当
コメント: