【发布时间】:2021-01-24 04:23:05
【问题描述】:
我有一个使用 Vuetify 的 Vue 应用程序。由于某种原因,v-chip 组件在绑定值更改时不会重新渲染。
<v-data-table>
<template v-slot:item.active="{ item }">
<v-edit-dialog :return-value.sync="item.active">
<v-chip :key="item.active" outlined :color="item.active ? 'success' : 'error'">{{ item.active ? "Open" : "Closed" }}</v-chip>
<template v-slot:input>
<v-switch
@change="saveRowField(item.id, 'active', item.active)"
v-model="item.active"
:true-value="1" :false-value="0"
color="success" label="Open"
></v-switch>
</template>
</v-edit-dialog>
</template>
</v-data-table>
v-edit-dialog 中的v-switch 正确更新了绑定字段item.active。然而,模板内的v-chip 组件不会在状态更改时重新呈现。
:key 属性绑定到与v-switch 相同的字段。
为什么当key绑定的值改变时v-chip没有重新渲染?
【问题讨论】:
-
为什么
:key在v-chip上?不需要 -
这是一种强制更新的技术
-
@DavidGo 好吧....不,不是
-
@DavidGo 好吧,仍然没有。 Vue 是否可以重用现有的组件实例是 提示。如果您需要触发生命周期钩子,它会很有用。如果您使用它“强制组件重新渲染”,那么它只是解决组件中其他一些反应性问题的“穷人”解决方法......
标签: vue.js vuejs2 vuetify.js