To use this.$store in Vue Component
bichikim opened this issue · comments
Bichi Kim commented
Set up as below code
import * as Sinai from 'sinai'
import aside from './aside'
import Vue from 'vue'
Vue.use(Sinai)
const root = Sinai.module().child('aside', aside())
export const store = Sinai.store(root, {
strict: process.env.DEV,
})
class Fake {
get store() {
return store
}
}
declare module 'vue/types/vue' {
interface Vue {
$store: typeof Fake.prototype.store
}
}
export default () => (store)
Now you can use this.$store like below
import {Component, Vue} from 'vue-property-decorator'
import store from 'src/store'
@Component
export default class IndexPage extends Vue {
meta: {
}
mounted() {
console.log(store().state.aside.version)
}
}
Katashin commented
Sorry, what do you mean by this issue? Is this a bug report or feature request? I don't understand what the intention of this issue is.
Bichi Kim commented
I'm sorry for not writing down my intentions.
I think this.$store
type checking is not working without below code
declare module 'vue/types/vue' {
interface Vue {
$store: typeof Fake.prototype.store
}
}
So Yes It just a tip for the problem
Katashin commented
Thanks for clarify. It's intentional not including the $store
type as store instance type is different between each app and users need to specify it by themselves.