在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ vue-cli 使用vuex 報錯store is not defined

vue-cli 使用vuex 報錯store is not defined

我配置完vuex后發(fā)現(xiàn)在組件內(nèi)無法使用

這是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>

然后就會報錯

clipboard.png

大佬們,這是我哪里配置的不對么,該如何修改

回答
編輯回答
吢涼

換成 this.$store.state.count試試

2017年11月1日 17:16