解决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'
      ])
    },
Logo

前往低代码交流专区

更多推荐