Answer the question
In order to leave comments, you need to log in
How to handle a direct jump to an address in a component?
Hello. I'm trying to make a skeleton application on vue. There was such a question.
there is a route - list of tasks
{
path: '',
name: 'tasks',
component: Tasks
}
<template>
<div>
<ul v-if="!tasks.isFetching">
<li v-for="task of tasks" > {{ task.name }}</li>
</ul>
</div>
</template>
<script>
import store from '../store/index'
export default {
beforeRouteEnter (to, from, next) {
store.dispatch('Tasks')
.then(() => {
next()
})
}
}
</script>
export default {
namespaced: true,
state: {
tasks: {}
},
mutations: { // Изменения Стора
tasks: function (state, data) {
for(let item of data){
state.tasks[item.pk] = item
}
},
},
actions: {
tasks: (context, filter) => {
axios.get('/tasks/').then((response) => {
context.commit('tasks', response.data)
})
},
}
}
Answer the question
In order to leave comments, you need to log in
You can try to look at two options:
1. whether isFetching works normally
2. reactivity may break when receiving data. Try to replace in the mutation with:
tasks: function (state, data) {
let res = {}
for(let item of data){
res[item.pk] = item
}
state.tasks = res
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question