【发布时间】:2018-04-18 17:16:28
【问题描述】:
我需要从Vuetify data table 中删除一个项目(行)。我正在使用来自vuex 的mapState 将数据表的items 属性绑定到一个名为screens 的计算变量。
<v-data-table
ref="dataTable"
v-bind:headers="headers"
v-bind:items="screens"
v-bind:search="search"
:loading="loading"
>
<template slot="items" slot-scope="props">
<tr @click="props.expanded = !props.expanded">
<td>{{ props.item.name }}</td>
<!-- etc -->
</tr>
</template>
<template slot="expand" slot-scope="props">
<screen-edit-form :screen-data="props.item"></screen-edit-form>
</template>
<template slot="pageText" slot-scope="{ pageStart, pageStop }">
From {{ pageStart }} to {{ pageStop }}
</template>
</v-data-table>
...
来自计算变量的片段
/**
* Automated the fetching of screen data.
*/
computed: mapState( {
screens: state => state.Screens.data
} ),
vuex 中的突变
/**
* Create an unset function using Lodash
* @param state
* @param payload
*/
unsetById: ( state, payload ) => {
// Remove the item
_.remove( state.data, { id: payload.id } );
// Emit an event to the event bus
EventBus.$emit( 'screen-deleted' );
}
数据表使用名为items 的模板槽和名为props 的槽范围。但是,每当我改变 screens 时,我可以看到 items 数组被正确更改(我从屏幕数组中删除的项目确实已经消失)但我对 DOM 没有反应。
我从docs 了解到,如果我想要双向绑定,我需要同步道具。我尝试在v-bind:items 上使用.sync 修饰符并使用this.$refs.dataTable.$emit( 'update:items', this.screens ); 发出更改,但无济于事。
任何有关使用插槽道具获得双向绑定的帮助将不胜感激。最终目标是能够从数据表中删除项目并将其立即反映在 DOM 上。
谢谢。
【问题讨论】:
标签: vue.js vuex two-way-binding vuetify.js