美文网首页
监听子组件值的变化

监听子组件值的变化

作者: 艾希_可可 | 来源:发表于2021-08-18 14:05 被阅读0次

    父传子prop
    子传父emit

    父监听子,可以用到hook,监听子组件数据的变化,也可以用vuex
    也可以用emit方法此处
    父组件

    <el-tab-pane name="fourth">
                <span slot="label">样车申请单<el-badge :value="VehicleApplyTodoNum" class="item" /></span>
                <VehicleApplyTodo ref="VehicleApplyTodo" @hook:updated="getVehicleApplyTodoNum" />
              </el-tab-pane>
    
    import VehicleApplyTodo from './component/vehiclemng/TodoEvent'
    export default {
      name: 'Dashboard',
      components: {
        VehicleApplyTodo
      },
      data() {
        return {
          VehicleApplyTodoNum: null
        }
      },
    method:{
    getVehicleApplyTodoNum() {
          this.VehicleApplyTodoNum = this.$refs.VehicleApplyTodo.vsapplytotal
        }
    }
    

    子组件

    data(){
    vsapplytotal:0
    }
    created() {
        this.getApplys()
      },
      methods: {
        async getApplys() {
          const res = await getVSAEvent(this.tbapplylistQuery)
          this.vsapplytotal = res.result.total
        }
    

    相关文章

      网友评论

          本文标题:监听子组件值的变化

          本文链接:https://www.haomeiwen.com/subject/nzegbltx.html