0

add.vue

<template>
    <div @click="add()">添加</div>
<template>
<script>
export fault{
    methods:{
        add(){
            this.$store.commit('point', event.target)
        }
    }
}
</script>

goods.vue

<template>

</template>
<script>
export falut{
    method:{
        play(el){
            for(let i=0;i<this.balls.length;i++){
                let ball =this.balls[i];
                if(!ball.show){
                   ball.show=true;
                   ball.el=el;
                   this.dropBalls.push(ball);
                   return;
                }
            }
        }
    }
}
</script>

goods.vue和add.vue是非父子隔层组件,之前用的全局变量监听事件做的,请问如何使用vuex实现 add组件传出参数,goods组件接收传入play方法并触发play方法执行?大神求解呀-_-|

查看全部 2 个回答

1

goods.vue

export default {
  computed: {
    pointData() {
      return this.$store.state.pointData;
    }
  },
  watch: {
    pointData(newVal) {
      this.play(newVal);
    }
  }
}