5
我有分量與守望`This`在vue.js未定義守望
props: {
propShow: { required: true, type: Boolean }
},
data() {
return {
show: this.propShow
}
},
watch: {
propShow: {
handler: (val, oldVal) => {
this.show = val;
}
}
}
每當parent
成分改變propShow
該組件必須更新它的show
財產。 This
組件也修改show
屬性,這就是爲什麼我需要兩個:show
和propShow
,因爲Vue.js不允許直接更改屬性。
此行
this.show = val;
導致錯誤
TypeError: Cannot set property 'show' of undefined
因爲this
內部處理程序是undefined
。
爲什麼?