使用了element ui。看文档可以用$on与$emit模拟双向绑定。但是似乎失败了。。两天了没解决,心好累。。
组件代码
methods: {
testChange(val){
this.$emit('testChange',val);
}
}
2.父级代码
import vueAddress from 'src/components/address'
components: {
vueAddress
},
data: function() {
return {
provinceValue:'全国',
cityValue:''
}
},
methods: {
testChange2(val){
this.provinceValue=val;
}
}
最后在父级点击组件依旧是
[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "provinceValue"
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
组件代码:
应该这样写
父组件:
原因:vue中$emit的写法并不支持驼峰,只能是全部小写,或者在分隔的地方用-
在子组件的方法中,写上$emit('你的子组件内方法'),父组件调用子组件用v-on:子组件方法名字="调用父组件方法"