vuejs / composition-api

Composition API plugin for Vue 2

Home Page:https://composition-api.vuejs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do I extend like this.$store in component?

kmq116 opened this issue · comments

I want to use like this.$store or this.$myCustom in .vue file ,but this occurs an Error with Vetur.
Property '$store' does not exist on type 'ComponentRenderProxy<unknown, { PAGE_TYPE: { CREATE: number; EXIST: number; SEARCH: number; }; }, { PAGE: number; exist: boolean; inputText: string; searchText: string; JDWD: any; existList: any[]; }, { headHeight(): "12.1%" | "7.4%"; mapCenterData(): any; }, { ...; }, unknown, {}, false>'.Vetur(2339)

I tried to use this method vue3 doc , but it didn't work. 🙄🙄🤞

The solution is to execute npm install vuex --save

If you're trying to do it in a setup function, I've had to do the following (although you get a note that it's deprecated syntax):

import {computed} from 'vue-composition-api'

// ... defineComponent or whatever you use ... 

    setup(props, context) {
      const store = context.root.$store
      const storeThing = computed( () => store.get('storeModule/thing') )

    // more setup code ...
   }
commented

I think you loose reactivity, getters seems not to be sync