Vue 3 aka

You might not need Vuex

Provide/Inject

Props

Props

Inject

export default {
  ...
  provide() {
    const machineState = {};
    Object.defineProperty(machineState,
      "condition", {
        enumerable: true,
        get: () => this.machineState
      }
    );
    return { machineState };
  }

}

export default {
  ...
  inject: ["machineState"]

}

Composition API

export const useMainStore = createStore({
  id: "main",
  state: () => ({
    machines: [...]
  }),
  actions: {
    getMachines() {
      ...
    }
  }
})
export default {
  ...
  setup() {
    const main = useMainStore()
    return {
      machines: main.state.machines,
      getMachines: main.getMachines
    }
  }
}

useMainStore.js

./components/component.vue

Vue 3 akaYou might not need Vuex

By shortdiv

Vue 3 akaYou might not need Vuex

  • 537