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>

[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,
    },

解决方法:

  1. 在子组件使用该值时需要经过新变量(chooseType)重新传递,这样当这个值变更时,不会造formData的更改
  2. 在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的使用不当


コメント:



(画像の文字列を入力して下さい)

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS