[Vuejs]-How to use Vue js global variables in pinia store?

1👍

With Pinia, you don’t have access to global properties. but it’s possible to pass using the use()

You will need to change the pinia code and add the context

  actions: {
    async fetchAvailableDates() {
      const response = await this.$http.get("get-dates");
      console.log(response.data);
    }
  }

On the main.js pass the properties, like this:

const pinia = createPinia();
pinia.use(({ store }) => {
  store.$http = app.config.globalProperties.$http;
});
app.use(pinia);

and use that you you want

Leave a comment