• vue子组件传值父组件,父组件传值子组件


    方法一子组件传值给父组件:
    this.$emit:子组件传值父组件
    this.$refs:父组件传值子组件
    子组件传值父组件
    this.$emit('getOrderDetailsList',InventoryInfo.orderDetailsList)
    父组件获取子组件的值
     <FormInfo ref="formInfo" @getOrderDetailsList="orderDetailsList" />
     
    orderDetailsList(res){
          this.$refs['formSKUInfo'].setData(res);
      this.data=res
        },
    formSKUInfo:子组件接收的值
    res:子组件传给父组件的值
    方法二父组件传值给子组件,子组件传值给父组件:
    父页面
    data(){
      return{
        relationMaterialNameList:true
      }
    }
    <editCost :tableData="tableData" @DraOpen1="getDraOpen1" :relationMaterialNameList="relationMaterialNameList"/>
    getDraOpen1(data) {
            this.DraOpen1 = data
    },
    子页面
    export default {
      //props:{
        //relationMaterialNameList:{
         // type:String,//String,Array,Object     
        //  default:false
       // }
      //}
    props:['relationMaterialNameList','tableData']
    }
     
     
    cancelFun() {
            this.$emit('DraOpen1', false)
     },
    子组件生命周期mounted获取值打印
    mounted() {
         let _this=this;
         let data=_this.relationMaterialNameList;
         console.log(data,999999);
       },
    如果还是获取不到其它获取方法链接https://www.cnblogs.com/wssdx/p/12373645.html

    方法
    三:通过ref获取子组件的方法传值:
    父组件:
    <!-- 详情页 -->
        <Drawer title="样衣详情" :closable="false" v-model="detailShow" width="75%">
          <detail ref = "detail"></detail>
      </Drawer>
     
    // 样衣档案
      import Detail from './detail/index'
     
     
     // 详情
          jumpDetail(id) {
            this.detailShow=true
    //获取子组件getInfo的方法并传值id
            this.$refs.detail.getInfo(id)
          },
    子组件:
    methods: {
    //接收父组件的值并赋值给this.sampleDevelopmentId
        getInfo (sampleDevelopmentId) {
          this.sampleDevelopmentId=sampleDevelopmentId
    }
    }
     
    方法四:watch监听获取父组件传的值
    子组件:
     props: ['switch', 'makeList','sampleDevelopmentId'], 
      watch: {
        switch: {
          handler (val, oldVal) {
            this.modal = val;
          }
        },
        sampleDevelopmentId: {
          handler (val, oldVal) {
            this.sampleDevelopmentId = val;
          }
        }
      },
    父组件
    <AddMake :switch="addMakeSwitch" :makeList="makeList" :sampleDevelopmentId="sampleDevelopmentId" @close="addMakeClose" />
     
     
  • 相关阅读:
    【JVM性能调优】检测最耗cpu的线程的脚本
    JUC之ThreadPoolExecutor实现原理
    HashMap实现原理
    JUC之阻塞队列BlockingQueue的实现原理
    dubbo实践
    .net 技术基础
    日志等级
    CentOS 笔记(六) 历史命令 自动补充
    CentOS 笔记(五) 常用工具
    CentOS 笔记(二) 端口占用,进程查看
  • 原文地址:https://www.cnblogs.com/wssdx/p/12074202.html
Copyright © 2020-2023  润新知