我正在尝试在带有打字稿的项目中使用Vuex 3.0.1和Vue 2.6.6。
store.ts
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
export const store = new Vuex.Store({
state: {
selectedComponent:'appParent'
}
});
main.ts
import Vue from 'vue';
import {store} from './store/store';
import App from './AppWP.vue';
public render(): void {
const id: string = `wp-${this.instanceId}`;
this.domElement.innerHTML = `<div id="${id}"></div>`;
let el = new Vue({
el: `#${id}`,
store,
render: h => h(App)
});
}
Player.vue
<template>
<div>
<div class="col-lg-4 col-md-6 mt-3">
<div class="card alert alert-success" style="width:170px">
<div class="card-body">
<button @click="selectComp">{{player.firstName}} {{player.lastName}}</button>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
props: ["player"],
methods: {
selectComp(){
this.$store.selectedComponent='appPlayerInfo';
}
},
};
</script>
<style>
</style>
我的问题:
$ store未定义
我已经看过很多问题,试图解决这个问题,但没有成功!