Let"s talk about the directory structure first:
src
api
login.js//
store
getters.js
index.js
modules
user.js
utils
request.js//axios
the problem is that now I want to use vuex, in request.js, but after I introduce it, I will always report an error: undefined, is that no matter how to write the path, I just can"t get it.
but, however, when I remove the reference interface in store/modules/user.js, I can get in request. I am very puzzled.
that is, I still can"t use the interface in vuex? This must be wrong. Paste the code
request.js:
import axios from "axios"
import store from "@/store"
console.log(store)// undefined!!
login.js
import request from "@/utils/request"
export function login(username, password) {
return request({
url: "/user/login",
method: "post",
data: {
username,
password
}
})
}
store/index.js
import Vue from "vue"
import Vuex from "vuex"
import user from "./modules/user"
import getters from "./getters"
Vue.use(Vuex)
const store = new Vuex.Store({
modules: {
user
},
getters
})
export default store
store/modules/user.js
import { login} from "@/api/login"
the point is, if I get rid of this sentence, I can get store in request.js
I still can"t figure it out all afternoon, call for help
after the great god reminded me, I posted the warning that webpack flashed and burst:
[HMR] Cannot apply update. Need to do a full reload!
[HMR] Error: Aborted because ./src/utils/request.js is not accepted
Update propagation: ./src/utls/request.js > ./src/api/mylogin.js ./src/permission.js ./src/main.js
at hotApply (http://L index/app.js:441:30)
at http://x/app.js:290:21