这里有几篇写的比较好的可以参考:
父子组件之间传值的几个坑:
- 父组件–》子组件(只有传值类型为Object的才能实现双向绑定,其他类型不可)
- eg:
-
Parent组件代码
-
<productclass :model="listQuery"/> listQuery: { v_productid: '', v_barcode: '', v_type: '', v_name: '', v_classname: '', v_classid: '', page: 1, limit: 10 }
-
Son组件代码 props: { model: { type: Object, required: true } } check(a, b) { const nodeL = this.$refs.tree.getCheckedNodes().length if (nodeL === 0) { this.$refs.tree.setCheckedNodes([]) this.model.v_classid = '' this.model.v_classname = '' } else if (nodeL === 1) { this.model.v_classid = a.id this.model.v_classname = a.label } else if (nodeL === 2) { this.$refs.tree.setCheckedNodes([a]) this.model.v_classid = a.id this.model.v_classname = a.label } }