vue实现双向绑定
v-bind:value=""
this.$emit('input')
watch: {
value(n) {
this.selected.idList = this.init(n)
}
},
methods: {
init() { // 在方法里处理监听的数据,(如果直接在value里处理数据可能会监听不到)
if(n){
if(this.type == "obj"){
return n.map(v => v[this.realField.id] - 0);
}
else if(this.type == "id"){
return n.map(v => v - 0);
}
else if(this.type == "ids"){
return n.split(",").map(v => v - 0);
}
else if(this.type == "json"){
return JSON.parse(n).map(v => v - 0);
}
}else{
return []
}
}
}
自定义组件加上v-model
最新推荐文章于 2024-04-09 14:48:57 发布