Recommand · October 22, 2021 0

Is it possible to use an injected store in vue3 with an external function?

In Vuejs3, "inject" is only possible in setup function,
but suppose you have a function that depends on injected store.

such as like this code.

setup(){
  const fooStore = inject(fooStoreKey);
  const barStore = inject(barStoreKey);

  const onClick = () => {
    fooStore.state.flag?
     barStore.actions.countUp():
      barStore.actions.countDown();
  }
}

Is it possible to make the above "onClick" an external function?