子组件
这里发现如果用原生的input的话直接使用$event.target.value
即可,但是如果使用vant的van-field的话就不行的,只能用$event才可以的
<div id="van-field-scan" v-cloak>
<div>
<van-field :value="value" :label="dlabel" @click-right-icon="scanQr()" clearable
right-icon="scan" placeholder="点击右侧图标识别" @input="$emit('input', $event)"></van-field>
<!-- <input @input="$emit('input', $event.target.value)"> -->
</div>
</div>
<script>
Vue.component('van-field-scan', {
template: '#van-field-scan',
props: {
value:{
type:String,
default:"ok"
},
dlabel:{
type:String,
default:"测试"
}
},
data(){
return{
value:"",
}
},
watch:{
value(newVal,oldVal){
console.log(newVal,oldVal);
console.log(this.$event);
}
},
methods:{
scanQr(e){
console.log(e);
wx.scanQRCode({
needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有
success: (res) => {
this.value = res.resultStr
this.$emit('input',res.resultStr);
}
});
}
}
})
</script>
不相信的话可以直接使用@input="test($event)"
来验证一下