import Vuex from 'vuex';
import Vue from 'vue';
Vue.use(Vuex);
const state = {
userName: '',
};
const mutations = {
FETCH_USERNAME_SUCCESS(state) {
state.userName = 'Jack';
},
};
export default new Vuex.Store({
state,
mutations,
strict: process.env.NODE_ENV !== 'production',
});
代码如上,运行性报错'state' is already declared in the upper scope
我必须要改一个写法,才能获取fetch回来的值:
import Vuex from 'vuex';
import Vue from 'vue';
Vue.use(Vuex);
const state = {
userName: '',
};
const mutations = {
FETCH_USERNAME_SUCCESS(a, res) {
state.userName = res.userName ;
},
};
export default new Vuex.Store({
state,
mutations,
strict: process.env.NODE_ENV !== 'production',
});