programing

Vuex 상태 boolen 속성이 정의되지 않음으로 표시됨

goodsources 2022. 11. 10. 20:55
반응형

Vuex 상태 boolen 속성이 정의되지 않음으로 표시됨

부울 상태 속성이 있는데 정의되지 않은 상태로 표시됩니까?

export default {
    state: {
        userStateChanged: false,
...

수행한 데이터를 가져오는 동안console.log이 상태 속성에서 콘솔이 정의되지 않은 상태로 표시됩니다.

        async FETCH_ALL_USERS(context, page) {

            console.log('state changed?', this.state.userStateChanged);

            if (this.state.userStateChanged === false) {
                return this.state.users;
            } else {
                console.log('return new set');
                const user  = await axios.get("/api/user?page=" + page);
                context.commit('SET_ALL_USERS', user.data);
            }
        },

다음을 통해 스토어 상태에 액세스해야 합니다.context.

async FETCH_ALL_USERS(context, page) {

            console.log('state changed?', context.state.userStateChanged);

            if (context.state.userStateChanged === false) {
                return context.state.users;
            } else {
                console.log('return new set');
                const user  = await axios.get("/api/user?page=" + page);
                context.commit('SET_ALL_USERS', user.data);
            }
        },

주에 액세스하기 전에 먼저 스토어에 액세스해야 합니다.그래서 대신console.log('state changed?', this.state.userStateChanged); 하다console.log('state changed?', this.$store.state.userStateChanged);

언급URL : https://stackoverflow.com/questions/62995735/vuex-state-boolen-property-shows-undefined

반응형