vue.js - strange behavior when trying to re-render data inside slot in vue
问题描述
I am getting strange behaviour when trying to dynamically update the content of a slot in Vue with Vuetify. I'm sure this is just a function of misunderstanding how slots work.
I have a slot in a custom component, like so:
<template #selectButtons="slotProps">
<v-icon @click="dropToggle(slotProps.player)"
:color="dropColor(slotProps.player)"
class="mr-5"
>
fas fa-skull-crossbones
</v-icon>
</template>
When the user clicks on the icon, it is meant to toggle the icon to different colors.
I cannot seem to get dropColor
to fire on each click consistently, HOWEVER, the weird part is, if I make some change inside the <v-icon>
component, like say I just add {{dropColor(slotProps.player)}}
inside the v-icon
tags, then all of a sudden the code will work.
But then if I do a full refresh of the page, it stops working. Then I delete that code and put it back in, then it works again!
I have tried forceUpdate and keys on the v-icon tag.
Would appreciate any help
解决方案
您正在尝试将功能dropColor(slotProps.player)
作为道具传递。更好的想法是将函数替换为对象或变量,并在事件触发dropToggle(slotProps.player)
后在方法内更改该对象/变量。@click
推荐阅读
- python - 从 request.FILES.getlist() 将视频保存到文件系统
- python - TemplateDoesNotExist 异常
- java - 硒网格指定平台
- c# - 共同朋友类的 C# 解决方法
- git - 卡在 git commit 中
- macos - 使用调试符号在 MacOS 上构建 Qt 应用程序
- azure-devops - 在 Devops 中,您如何像在 MTM 中一样将测试计划套件置于 Alpha 顺序中?
- javascript - Vue 对象中的计算值函数被触发
- matlab - parfor 在计算机上像普通的 for 循环一样执行吗?
- elasticsearch - Elasticsearch 搜索模板在尝试渲染时导致“不正确地关闭变量”