【vue】父子组件之间通信


使用场景:

  • 几个页面有相同的布局
  • 在子组件筛选的时候触发父组件中的列表数据

父组件:father.vue

<sun ref="select" @handleselectdata="handleselectdata">sun>

js

handleselectdata(){
    alert(1);
},

子组件:sun.vue


遇到的问题1:

父组件通过ref访问子组件中的数据

const childrenData = this.$refs.select.orderSelect;

报错

 解决方案:

this.$nextTick(()=>{
    const childrenData = this.$refs.select.orderSelect;
})

问题2:子组件触发父组件中的方法,加自定义方法 @handleselectdata="handleselectdata"

子组件中的this.$nextTick可以不加,再次复看的时候,不加也能实现,不晓得为什么

搜索

复制

vue