情况 : 一个v-model,由2个变量拼接 ( deviceSnstr = str16a + str16b;)
<el-input v-model="deviceSnstr" placeholder="请输入" />
第一种:computed
data里不能声明变量, 不watch监听变量
data:{
str16a :null,
str16b :null
},
computed: {
deviceSnstr: {
get() {
return this.str16a + this.str16b
},
set(val) {
this.deviceSnstr = val
}
}
},
第二种: watch
data里要声明3个变量
data:{
str16a :null,
str16b :null,
deviceSnstr :
},
watch: {
str16a(newVal, oldVal) {
this.deviceSnstr = newVal + this.str16b
},
str16b(newVal, oldVal) {
this.deviceSnstr = this.str16a + newVal
},
},