在vue中v-model绑定了一个值到val中,用到了计算属性监测val的变化,但是使用了computed之后,v-model的双向绑定失效
<div class = "flex f7" style = "width: 0" v-if="isIos || isAndroid">
<input class = "f7" type = "text" v-model = "getAddress" :placeholder = "$t('withdraw.adsToast')"/>
<div class = "f1 img-cont" @click = "scan()">
<img src = "../../assets/img/ic-withdrawAds.png"
class = "ic-ads"/>
</div>
</div>
computed: {
getAddress() {
if(this.$store.state.updateAddress){
this.address = this.$store.state.updateAddress
}
return this.$store.state.updateAddress;
},
},
输入地址之后再输入下面其他input值,地址值变为空,打印this.address为空
后来在计算属性中加入get和set解决了双向绑定问题
computed: {
getAddress: {
get: function () {
if(this.$store.state.updateAddress){
this.address = this.$store.state.updateAddress
}
return this.address
},
set: function (value) {
this.address = value
},
},
},