【发布时间】:2022-08-16 10:57:47
【问题描述】:
我想创建一个表,当项目更新时,该行会闪烁一次。
我设法在组件启动时使一行闪烁,但在更新值时它不会闪烁。
我创建了一个带有两个 css 类的示例(仅用于测试),一个闪烁一次,另一个闪烁无限。
如果我们更新项目值,我们可以看到无限仍然闪烁并随着条件的填充而改变行,但是应该闪烁一次的项目没有改变。
任何帮助将不胜感激。
Vue.config.productionTip = false;
Vue.config.devtools = false;
new Vue({
el: \'#app\',
vuetify: new Vuetify(),
data() {
return {
items: [{
id: 1,
name: \'Frozen Yogurt\',
calories: 159,
},
{
id: 2,
name: \'Ice cream sandwich\',
calories: 237,
},
{
id: 3,
name: \'Eclair\',
calories: 262,
},
{
id: 4,
name: \'Cupcake\',
calories: 305,
},
],
headers: [{
text: \'Dessert\',
value: \'name\',
},
{
text: \'Calories\',
value: \'calories\'
},
],
};
},
methods: {
blink(item) {
if (item.calories > 200){
return \'blink-great\';
} else {
return \'blink-less\';
}
},
getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
},
updateValues() {
const newValues = this.items.map((el) => {
return {...el, calories: this.getRandomInt(100,500)};
})
this.items = newValues
}
},
computed: {
displayItems() {
var newItems = this.items.map((el) => {
return {...el, calories: el.calories * 1};
})
return newItems
}
},
});
.blink-less {
animation: blinking ease-out 1s 3;
--background-color: #FF0000
}
.blink-great {
animation: blinking ease-out 1s infinite;
--background-color: #0000FF
}
@keyframes blinking {
0% {
background-color: var(--background-color);
}
100% {
background-color: #fff;
}
}
<link href=\"https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900\" rel=\"stylesheet\">
<link href=\"https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css\" rel=\"stylesheet\">
<link href=\"https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css\" rel=\"stylesheet\">
<script src=\"https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js\"></script>
<script src=\"https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js\"></script>
<div id=\"app\">
<v-app>
<v-container>
<v-row class=\"pa-5\">
<v-btn
@click=\"updateValues()\"
> Update value </v-btn>
</v-row>
<v-row class=\"px-5\">
<v-data-table
hide-default-footer
:headers=\"headers\"
:items=\"displayItems\"
:item-class=\"blink\"
/>
</v-row>
</v-container>
</v-app>
</div>
标签: css vue.js vuejs2 vuetify.js css-animations