Man*_*lli 5 vue.js vuex sortablejs vuetify.js vue-data-tables
我正在使用 V-data-table 和 vuex 存储。以下是我如何配置 v-data-table 的要点
问题: 当我拖放 v-data-table 中的行时,我正在更新 vuex 存储(使用表行索引值更新数组中对象的索引值)。Vuex 正在正确更新,但在 v-data-table 中呈现的数据与它们在 vuex 状态存储中的顺序不一致
有人可以帮助我吗
我试图克服这个问题的最好方法是强制重新渲染 v-data-table 组件,但是当我这样做时,我不能再拖放了
使用以下模板强制渲染
<template>
<component-to-re-render :key="componentKey" />
</template>
// script
export default {
data() {
return {
componentKey: 0,
};
},
methods: {
forceRerender() {
this.componentKey += 1;
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 2
这可能不是最佳解决方案,但我遇到了类似的问题,除了我只是使用常规数组。我设法通过调用 update() 生命周期挂钩中的 Sortable.create() 方法来修复它。
我的猜测是,当您调用 Sortable.create(table, ...) 时,它引用 table 元素的该实例。但是,当您尝试通过修改键来更改表时,它会更改该实例。因此,每当vue组件更新时,您都需要再次调用Sortable.create()。
| 归档时间: |
|
| 查看次数: |
4802 次 |
| 最近记录: |