Answer the question
In order to leave comments, you need to log in
How to solve this object reactivity problem in vuex?
Good evening!
Google has already broken its head with this problem, immediately to the code:
There is a component that sends post data to vuex:
<template>
<div v-for="post in content_data" :key="post.id">
<!-- content_data это очевидно массив с постами -->
<!-- Просто фиксирую внимание, так как дальше фигурирует данный массив в описании -->
<button @click="post_edit(post)">
<p>
Редактировать
</p>
</button>
</div>
</template>
<script>
export default{
props:['post', 'content'],
methods:{
post_edit(i){
this.$store.dispatch('full_view', {i:2,d:i})
}
}
}
</script>
export default{
state:{
full_view_id: 0,
full_view_data: false
},
getters:{
full_view_id:(state)=>state.full_view_id,
full_view_data:(state)=>state.full_view_data
},
actions:{
full_view({state}, d){
state.full_view_id=d.i
if(d.d){
state.full_view_data=d.d
}else{
state.full_view_data=false
}
}
}
}
{
'text':'Hello World!',
'files':[{'id':0,'filename':'helloworld.jpg'}]
}
'files':[{'id':0,'filename':'helloworld.jpg'}]
in 'files':[{'id':0,'filename':'goodbyeworld.jpg'}]
, well, when the component memory is updated, the content_data array is updated . data(){
return{
post_data: this.$store.getters.full_view_data
//{
// 'text':'Hello World!',
// 'files':[{'id':0,'filename':'helloworld.jpg'}]
//}
}
},
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question