我配置完vuex后发现在组件内无法使用
这是main.js
import Vue from 'vue'
import 'es6-promise/auto'
import App from './App'
import router from './router'
import vuex from 'vuex'
/* eslint-disable no-new */
Vue.use(vuex);
var store = new vuex.Store({//store对象
state:{
show:"aaaaaaa"
}
})
new Vue({
el: '#app',
router,
store,//使用store
components: { App },
template: '<App/>'
})
helloworld.vue
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<h2>Essential Links</h2>
<h1>11111{{store.state.count}}</h1>
</div>
</template>
<script>
export default {
created(){
this.fetchData()
},
watch:{
'$route':'fetchData'
},
methods:{
//路由越换
fetchData(){
console.log("1111")
console.log(store.state.count)
},
},
name: 'HelloWorld',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
},
}
</script>
然后就会报错
大佬们,这是我哪里配置的不对么,该如何修改
换成
this.$store.state.count
试试