vuex getters和mapGetters 视图不更新的问题
import { getInfo } from "@/api/user";import Vue from "vue";const state = {ExchangePointMinLimitValue: ""};const mutations = {SET_EXCHANGEPOINTLIMITVALUE: (state, exchangepointminlimitva...
·
解决vuex getters和mapGetters 视图不更新的问题:
需要用Vue.set
import { getInfo } from "@/api/user";
import Vue from "vue";
const state = {
ExchangePointMinLimitValue: ""
};
const mutations = {
SET_EXCHANGEPOINTLIMITVALUE: (state, exchangepointminlimitvalue) => {
// state.exchangepointminlimitvalue = exchangepointminlimitvalue; 这样写,视图不更新
// **需要用Vue.set**
Vue.set(state,'exchangepointminlimitvalue',exchangepointminlimitvalue)
console.log('exchangepointminlimitvalue',exchangepointminlimitvalue);
}
};
const actions = {
// get user info
getInfo({ commit, state }) {
return new Promise((resolve, reject) => {
getInfo()
.then(response => {
const data = response.return_data;
const exchangepointminlimitvalue = data.exchangepointminlimitvalue;
commit("SET_EXCHANGEPOINTLIMITVALUE", exchangepointminlimitvalue);
resolve(data);
})
.catch(error => {
reject(error);
});
});
}
};
export default {
namespaced: true,
state,
mutations,
actions
};
页面
import { mapGetters } from 'vuex'
computed: {
...mapGetters([
'exchangepointminlimitvalue'
])
},
更多推荐
已为社区贡献12条内容
所有评论(0)