2017-12-24 37 views
0

Axios에서 문제가 발생합니다. Vuex에서 머리글 가져 오기 - VueJS, 여러분이 도와 주길 바랍니다.Axios Vuex에서 머리글 가져 오기 - NUXTJS

페이지 :

<template> 
<div class="temp">{{users.info}}</div> 
</template> 

<script> 
data: function() { 
    return { 
     config: { 
     'headers': {'Authorization': 'JWT ' + this.$store.state.token} 
     } 
    } 
    }, 
fetch ({ store, params }) { 
    return store.dispatch('getProfile', params, this.config) 
    }, 
</script> 

Vuex 모듈 :

import api from '~/plugins/axios' 

const state =() => { 
    return { 
    info: null 
    } 
} 

const actions = { 
    getProfile ({commit}, params, config) { 
    return new Promise((resolve, reject) => { 
     api.get(`/users/${params.username}/`, config) 
     .then(response => { 
     commit('GET_USER_DETAIL', response.data) 
     resolve(response.data) 
     }, 
     response => { 
     reject(response.data) 
     }) 
    }) 
    } 
} 
const getters = {} 

const mutations = { 
    GET_USER_DETAIL (state, info) { 
    state.info = info 
    } 
} 

export default { 
    state, 
    actions, 
    getters, 
    mutations 
} 

문제 : Vuex 모듈 설정이 정의되어 있지 않습니다.

나는 당신의 도움을 바라는 뭔가 잘못 생각합니다. 미리 감사드립니다.

답변

2

Vuex의 작업에는 둘 이상의 매개 변수를 사용할 수 없습니다. 그래서 같은 단일 개체로 당신의 PARAMS 그룹 최대 :

return store.dispatch('getProfile', { params: params, config: this.config }) 

는 다음과 같이 액션에서 액세스 : 당신이 docs에서 작업을 파견 섹션을 보면

getProfile ({commit}, obj) { 
    var params = obj.params 
    var config = obj.config 
    /* ... */ 
} 

올바른 방법을 보여줍니다 매개 변수를 전달합니다.

+0

많은 분들께 감사드립니다. :) –