Vuex this.$store undefined

浅浅记录一下问题, this.$store 一直都是 undefined 

最后的解决办法:

Vuex的版本过高,是vuex:4.0.2,而我用的是Vue2,使用vue2对应的vuex应该为vuex3,

vue3对应的版本为Vuex4 

store/index.js

import Vue from 'vue';
import Vuex from 'vuex';
 
Vue.use(Vuex);
 
let items = [{"id":3,"name":"Macbook Pro 15.4","vendor":"Apple","price":1949900},{"id":4,"name":"Apple iMac","vendor":"Apple","price":1629900},{"id":9,"name":"游戏本2019款","vendor":"XiaoMi","price":879900},{"id":6,"name":"Apple Watch Series 4","vendor":"Apple","price":599900},{"id":1,"name":"iPhone XR","vendor":"Apple","price":542500},{"id":11,"name":"HUAWEI P30 Pro","vendor":"HuaWei","price":498800},{"id":2,"name":"Apple iPad Air 3","vendor":"Apple","price":377700},{"id":10,"name":"HUAWEI P30","vendor":"HuaWei","price":368800},{"id":7,"name":"小米9","vendor":"XiaoMi","price":259900},{"id":12,"name":"华为平板 M6 10.8英寸","vendor":"HuaWei","price":229900},{"id":16,"name":"Redmi K20","vendor":"XiaoMi","price":199900},{"id":13,"name":"HUAWEI WATCH GT","vendor":"HuaWei","price":128800},{"id":5,"name":"Apple Magic Mouse","vendor":"Apple","price":72900},{"id":8,"name":"小米手环4","vendor":"XiaoMi","price":16900}];
 
let store = new Vuex.Store({
    state: {
        items
    }
});
 
 
export default store

main.js

import Vue from 'vue'
import App from './App.vue'
import axios from 'axios'
import mock from './mock'
import store from './store'

Vue.prototype.$axios = axios

new Vue({
  el: '#app',
  store,
  render: h => h(App)
})

app.vue

<template>
  <div>
    <!-- <div>{{ storeData }}</div> -->
  </div>
</template>

<script>

export default {
  name: 'countup-demo',
  data () {
    return {
      // storeData: this.$store.state.count
    }
  },
  created () {
    console.log('ddddd---', this.$store);
  },
 
}
</script>

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值