watch: {
'detailData.swcarno': (val) => {
const upperCase = val.toUpperCase()
this.detailData.swcarno = upperCase
}
},
这里控制台报错
TypeError: Cannot read properties of undefined (reading 'detailData')
这里报错undefined,这里错误的原因是不能写成箭头函数。写成箭头函数后,this会取上下文,而不是组件里面的this了,正确写法为:
watch: {
'detailData.swcarno': function (val) {
const upperCase = val.toUpperCase()
this.detailData.swcarno = upperCase
}
},
网友评论