vue 祖先和后代之间传值 provide inject dispatch


祖先--后代 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}`
        })
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM