Vue.js Quasar(vue)路由器中嵌套的父/子触发器方法

Vue.js Quasar(vue)路由器中嵌套的父/子触发器方法,vue.js,vuex,vue-router,vuejs3,vuex4,Vue.js,Vuex,Vue Router,Vuejs3,Vuex4,我使用Quasar框架(vue 3)在路由器中获得了嵌套路由的结构: 我知道我可以在我的孩子中使用$emit传递给家长,如下所示: 我的孩子: this.$emit("myEvent", "hello world"); <MyChild @myEvent="updateMyEvent" /> MyParent: this.$emit("myEvent", "hello world&q

我使用Quasar框架(vue 3)在路由器中获得了嵌套路由的结构:

我知道我可以在我的孩子中使用$emit传递给家长,如下所示:

我的孩子:

  this.$emit("myEvent", "hello world");
<MyChild @myEvent="updateMyEvent" />
MyParent:

  this.$emit("myEvent", "hello world");
<MyChild @myEvent="updateMyEvent" />
Store.js

vuex:
const state = {
  value: 0
};

const actions = {
  updateValue({ commit }, payload) {
    commit("updateMyValue", payload);
  },

const mutations = {
  updateMyValue(state, payload) {
    state.myValue = payload;
  },
};

const getters = {
  getValue: state => {
    return state.value;
  },

事实上,我在我父母的getter上找到了一个观察者:

  computed: {
    ...mapGetters("store", ["getValue"]) // module and name of the getter
  },
  watch: {
    getValue(val) {
      console.log("MY VALUE: " , val);
    }

在子父组件中,定义一个名为
stateValue
的计算属性,该属性基于存储状态值,然后观察它触发该事件:

computed:{
   stateValue(){
     return this.$store.state.value;
   }
},
watch:{
    stateValue(val){
     this.updateMyEvent()// trigger the method
   }
}

我建议使用事件总线,我可能会混合这些概念,但不可能通过vuex?当状态改变时触发一个方法?是的,这是一个完美的方法,它比使用事件总线更好,请分享这个状态完美。那我该怎么做呢?查看上面我的vuex更新我的父母在我的getter上有一个观察者在观察vuex中的getter,请参见上面我的更新