In vuex, store cannot be registered with vue. This.$store is empty.

my main.js goes like this:



import Vue from "vue"
import Vuex from "vuex";
import App from "./App"
import router from "./router"

//import store from "./store/vuexstore.js"//vuexstore.js 

Vue.config.productionTip = false

/*****/
Vue.use(Vuex)
let state={  
    cartData:[]
};
let mutations = {
    updateCartData(state, _cartData){
        state.cartData = _cartData;
    }
}
var store=new Vuex.Store({
    state,
    mutations
})

/*****/


new Vue({
  el: "-sharpapp",
  router,
  store,//store
  components: { App },
  template: "<App/>"
})
 console.log( store);// Vuex.Store
 console.log( this.$store,Vue.$store);//2undefined
console.log( vue.prtotype);//vue$route$store

you can also see the vuex project in Google"s vue debugging plug-in, but calling this.$store in the code can"t solve ~
Thank you in advance! ~

clipboard.png

Jun.13,2022

your this in main.js does not point to the vue instance, but the Vue points to the Vue constructor. Of course, there is no store object in it. You can print it in the specific vue instance. Or

let myVue = new Vue({
  el: '-sharpapp',
  router,
  store,//store
  components: { App },
  template: '<App/>'
})
console.log(myVue.$store)

now you can see the store object

Menu