zoukankan      html  css  js  c++  java
  • 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}`
            })
        }
  • 相关阅读:
    bzoj1221
    hdu3377
    bzoj3930
    bzoj3976
    bzoj4237
    fzu1977
    hdu1693
    ural1519
    bzoj1264
    回答自己的提问
  • 原文地址:https://www.cnblogs.com/1032473245jing/p/12787561.html
Copyright © 2011-2022 走看看