export default {
[type.GET_PAPERS] (state, force = false) {
fetch(`${apiUrl}/api/paper`).then(r => r.json())
.then(data => state.papers = data) // Error: [vuex] Do not mutate vuex store state outside mutation handlers.
// state.papers = [1, 2, 3, 4] // ok
}
}
请仔细看文档。mutation 必须同步,任何异步只能出现在 action 里。
作者 亲自评论。好厉害啊
Most helpful comment
请仔细看文档。mutation 必须同步,任何异步只能出现在 action 里。