vue组件 子组件没有事件怎么 向父组件传递数据

 

通过ref去接收值!!! 

需求图片

 

 

 

 

代码实现

 

 //----------父组件
<div class="fingerprint-bottom"> <el-tabs v-model="activeName"> <el-tab-pane v-for="(item,index) in optionS" :key="index" :label="item.label" :name="item.name"> <EditAssetTab :ref="item.type" type="item.type" :edit-asset-data="editAssetData" :active-name="item.name" /> </el-tab-pane> </el-tabs> </div>


// 提交按钮
   submitAsset() {
      // 调用子组件的获取数据方法
      const refsMap = ['a', 'b', 'c', 'd', 'e', 'f'];
      refsMap.map(item => {
        this.originData = { ...this.originData, ...this.$refs[item].getAllQuery() };
      });

 

// ------子组件

//获取组件所有参数
 getAllQuery() {
      if (this.type === 'a') { // a->为父组件的ref的值
        return {
          ip_type: this.ip_type, // IP类型
          ip_nat: this.ip_nat, // 映射IP
        };
           ............
}

  

posted @ 2023-01-03 16:57  小十六哇  阅读(158)  评论(0编辑  收藏  举报