0
値Iがセットアップvuexを持っていると私は後でデータを取得し、私のフォームモデルを更新したいと思いますが、これが今の私のvuexVueのJS2 vuex形態V-モデルは
//state
const state = {
profile: [],
}
//getter
const getters = {
profileDetails: state => state.profile,
}
//the actions
const actions = {
getProfileDetails ({ commit }) {
axios.get('/my-profile-details')
.then((response) => {
let data = response.data;
commit(types.RECEIVED_USERS, {data});
},
);
}
}
const mutations = {
[types.RECEIVED_USERS] (state, { data }) {
state.profile = data;
state.dataloaded = true;
},
}
で
を失敗した更新私はvuexがデータを持っていますが、私のコンポーネントは、データをフェッチするために、アクションでの発送を呼び出した後vuexでデータをフェッチ傾けることがわかりますVUEの開発ツールでチェックすることにより、私のVUEのJSファイル
export default{
data:() => ({
profile_form:{
nickname:'',
first_name:'',
last_name:'',
email:''
}
}),
computed:{
...mapGetters({
user: 'profileDetails',
}),
},
methods:{
setUpDetails(){
this.profile_form.email = this.user.email; //the value is always undefined
}
},
mounted(){
this.$store.dispatch('getProfileDetails').then(
(res)=>{
console.log(res); //this is undefined
this.setUpDetails(); ///this is never executed
}
);
this.setUpDetails(); //tried adding it here
}
。
どこが間違っていますか。
のNb:
<input v-model="profile_form.email" >