【发布时间】:2021-04-25 05:11:32
【问题描述】:
当我的store 中的数据更新时,我在重新渲染我的table 组件时遇到问题,
我有一张带有v-for 的简单表格,如下所示:
<tr v-for="d in getDatas" v-bind:key="d.id">
和改变页面的按钮:
<button class="fa fa-chevron-left" @click="previousPage"/>
<button class="fa fa-chevron-right" @click="nextPage"/>
我在打开组件之前将数据加载到我的数据中,这个表在哪里,我从存储中获取这些数据,如下所示:
computed: {
getDatas () {
return this.$store.getters.getDatas;
}
},
但是当我点击按钮nextPage 或previousPage 时,如何使用data 更新我的商店?
这是我的方法:
methods: {
...mapActions(["fetchDatas"]), //this is my action
nextPage() {
this.currentPage += 1;
},
previousPage() {
if(this.currentPage != 1) {
this.currentPage -= 1;
}
},
和我的行动:
async fetchDatas({ commit },{ currentPage}) {
const data = await fetch(`someURL&perPage=${currentPage}`);
const response = await data.json();
commit('setData', response);
}
那么,当我点击我的next/previousPage 时,如何重新加载组件和我的商店?
【问题讨论】:
标签: javascript typescript vue.js vuex