Get the getters,Cannot read property 'getters' of undefined of store

uses the login permission judgment in vue-element-admin, which is basically introduced and loaded according to it, but it still prompts you to report an error
main.js

.
import Vue from "vue"
import App from "./App"
import router from "./router"
import store from "./store"

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: "-sharpapp",
  router,
  store,
  components: { App },
  template: "<App/>"
})

login.vue

export default {
  data () {
    return {
      userName: "",
      passWord: ""
    }
  },
  methods: {
    verify () {
      if (this.userName === "") {
        mui.toast("", { duration: "long", type: "div" })
        return false
      }
      if (this.passWord === "") {
        mui.toast("", { duration: "long", type: "div" })
        return false
      }
      return true
    },
    login () {
      let result = this.verify()
      if (result) {
        let data = {
          username: this.userName,
          password: this.passWord
        }
        this.$store.dispatch("LoginByUsername", data).then(() => {
          this.$router.push({ path: "/" })
          // mui.toast("", { duration: "long", type: "div" })
        }).catch(() => {
          // mui.toast(res.msg, { duration: "long", type: "div" })
        })
      } else {
        console.log("error submit!!")
        return false
      }
    }
  }
}

login.js

import request from "@/utils/request"
export function loginByUsername (username, password) {
  const data = {
    username,
    password
  }
  return request({
    url: "/User/login",
    method: "post",
    data
  })
}

user.js

import { loginByUsername, logout, getUserInfo } from "@/api/login"
import { getToken, setToken, removeToken } from "@/utils/index"
  actions: {
    // 
    LoginByUsername ({ commit }, userInfo) {
      const username = userInfo.username.trim()
      return new Promise((resolve, reject) => {
        loginByUsername(username, userInfo.password).then(response => {
          const data = response.data
          console.log(data)
          commit("SET_TOKEN", data.token)
          setToken(response.data.token)
          resolve()
        }).catch(error => {
          reject(error)
        })
      })
    }
 }

request.js

import axios from "axios"
import mui from "mui"
import store from "@/store"
import { getToken } from "@/utils/index"
// request interceptor
service.interceptors.request.use(config => {
  // Do something before request is sent
  if (store.getters.token) {
    // token-- ["X-Token"]key 
    config.headers["XX-Token"] = getToken()
  }
  console.log("token +".store.getters.token)
  return config
}, error => {
  // Do something with request error
  console.log(error) // for debug
  Promise.reject(error)
})

then when you request, you always get the wrong Cannot read property "getters" of undefined

.
Mar.21,2021

it should be that the introduction path of store in request.js is wrong, or the data in the store directory is not successfully exported, so store becomes an error when undefined, calls getters to report an error


request.js printing. There is an obvious error in front of store.


after you introduce store in main.js, you can call the token method
through this.$store.getters.token or

within the component.
import { mapGetters } from 'vuex'
methods: {
    ...mapGetters(['token']),
}

adjust this.token () in the component


your store.js has not been posted either. It should not be written correctly

.
const store = new Vuex.Store({
  state: {
    // token: ''
  },
  getters: {
    token: (state, getters) => {
      return 'token'
    },
    roles: (state, getters) => {
      return []
    }
  }
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf2cce-31e32.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf2cce-31e32.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?