我有一个用户列表,我正在尝试添加一个图标来启用/禁用他们的帐户。所以我在 v-for 循环中呈现用户列表。我使用循环索引索引的数组跟踪每个图标上徽章的可见性。
我遇到了一个奇怪的问题,除非我更新其他一些虚拟变量,否则 Vue 无法识别对数组值的更改。这是一个 Vuetify 问题吗?还是只是 Vue 反应性问题?
我创建了一个 Codepen 来显示我的问题。 https://codepen.io/DedicatedManager/pen/eYmZRQo?editors=1010
<div id="app">
<v-app id="inspire">
<v-container fluid class="text-center">
The two lists are the same differing only by changing a dummy variable in the "mouseover" and "mouseout" function that causes the badge to display/hide. But the one on the left doesn't show the badge on hover. The one on the right has the extra dummy variable that somehow forces the rendering to work and thus the badge shows (it shows on both sides because they use the same variable to hold the boolean for the v-model.
<v-row
justify="space-between"
>
<v-col cols="6" class="mt-12">
<div v-for="(listItem,index) in myData" :key="index">
<v-badge v-model="showCircle1[index]" overlap>
<template v-slot:badge>
<span><v-icon>mdi-delete</v-icon></span>
</template>
<v-icon large color="grey" @mouseover="showCircle1[index]=true;" @mouseout="showCircle1[index]=false;">mdi-email</v-icon>
</v-badge>
</div>
</v-col>
<v-col cols="6" class="mt-12">
<div v-for="(listItem,index) in myData" :key="index">
<v-badge v-model="showCircle1[index]" overlap>
<template v-slot:badge>
<span><v-icon>mdi-delete</v-icon></span>
</template>
<v-icon large color="grey" @mouseover="showCircle1[index]=true; mouseOverVal=true" @mouseout="showCircle1[index]=false; mouseOverVal=false">mdi-email</v-icon>
</v-badge>
</div>
</v-col>
</v-row>
mouseOverVal: {{mouseOverVal}}<br>
showCircle1: {{showCircle1}}<br>
</v-container>
</v-app>
</div>
Javascript
new Vue({
el: '#app',
vuetify: new Vuetify(),
data () {
return {
showCircle1:[false,false,false,false],
myData:['one','two','three','four'],
mouseOverVal:false,
}
},
})