在第一次加载vuex时声明状态doenst返回数据

时间:2019-06-24 19:48:03

标签: vuejs2 vuex

我有一个名为this.userList的列表,可用于在此视图上填充表。我的问题是,此列表的每个首次加载在Index.vue中都是空的。

在actions.js中,我在服务上请求的数据可以,并且当我提交该数据时,列表可以正常工作。但是,当我在计算计算机上调用...mapState('selectedLocation',['selectedLocation']),时,视图就空了。我真的不知道我在这里想念什么。这是一些代码:

Index.vue

<m-table :listItems="formatedList" 
        :delButton="true" 
        :editButton="true" 
        :detailsButton="false"
        :detailsButtonMessage="$t('views.users.edit')"
        :fields="fields" 
        @delete="deleteRow" 
        @edit="editRow"/>

computed: {
    ...mapState('users',['userList','userFormState']),
    formatedList() {
        if(this.userList.data) {
            this.userList.data.items.forEach((user, index) => {
                let profileId = user.Profiles[0].Profile - 1
                user['profileName'] = this.$t(`profiles[${profileId}].text`)
            })

            return !this.profilesSelect.length ? this.userList.data.items : this.userList.data.items.filter(
                ({profileName}) => this.profilesSelect.find(profile => profile.Name === profileName))
        }
    },
}

methods: { 
    fetchData(){
        this.$store.dispatch('users/read');
    },
}

mounted(){
    this.$store.dispatch('genericTable/clearGenericTable');
    this.fetchData();
    this.fecthFilters();
}

actions.js

async read({ dispatch , rootState }, idLocation = '',updatedParams = false){
    const { qCurrentPage , selected } = rootState.genericTable
    let params = updatedParams ? updatedParams : {
        qCurrentPage,
        qPageSize: selected,
        includeDeleted: false,
        qStatus: true,
    }
    params['locationId'] = rootState.selectedLocation.selectedLocation.PublicId
    params['qProfiles'] = [0,1,2,3,6,8]
    let { data } = await User_GetUsersByLicenseeAndProfile(params)
    const formatedUser = []
    dispatch('setUserList', data)
},
setUserList({ commit },data){
    commit(mutations.FETCH_USERS, data)
},

mutations.js

    [mutations.FETCH_USERS]: (state, payload) => state.userList = payload,

state.js

export default{
    userList: [],
    userFormState: {
        Name: '',
        Email: '',
        Gender: 0,
        Matriculation: '',
        UserName: '',
        Telephone: '',
        Status: true,
        Level: 1,
        HasRegistered: false,
        LoginProvider: 'api',
        Password: '',
    },
}

在actions.js中,例如,如果我使用console.log(data),则有清单。问题是当我从视图中获取列表时。

0 个答案:

没有答案