祖先--后代 provide inject

index.js

provide: {
        indexVal: 'indexVal--grandson1'
    },

grandson.js

<div>{{indexVal}}</div>

inject: ['indexVal'],

 

后代--祖先 dispatch

grandson.js

<div @click="dispatchClick">dispatch</div>

methods: {
        dispatchClick() {
            this.$dispatch('dispatch', 'grandson1--indexVal')
        }
    }

index.js

<div>{{msg}}</div>

data() {
        return {
            msg: ''
        }
    },
    mounted() {
        this.$on('dispatch', msg => {
            this.msg=`从grandson接收到的数据${msg}`
        })
    }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
  • 2021-08-01
猜你喜欢
  • 2022-01-15
  • 2021-09-07
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-14
相关资源
相似解决方案