vue.js - How to specify "key" as a required prop?
问题描述
I want this
export default {
props: {
key: {
type: String,
required: true,
},
},
...
}
But it leads to a runtime error:
[Vue warn]: "key" is a reserved attribute and cannot be used as component prop.
EDIT:
To clarify: I want the reserved attribute "key" to be required. This is because my component relies on the trick of "Forcing component recreation by key change". (link)
解决方案
key
是Vue.js 保留的特殊属性之一。
它不能作为, 和, , ,prop
一样传递。ref
slot
scoped-slot
is
只需将 重命名prop
为您选择的任何名称。
如果命名属性的使用key
在子组件内至关重要,则可以key
在子组件内创建一个计算属性,该属性将从传递的值返回,prop
并可在子组件内访问。
推荐阅读
- node.js - Mongoose:如何更新嵌套数组?
- python - 将数据从另一个数组填充到数组
- python - Python:-'Book'对象没有属性'add_format'
- vba - 根据收件人主动更改电子邮件签名
- python - 如何将python中的stdout重定向到函数?
- wordpress - 如何在 corcel / acf 上获取 ACF 组字段值?
- c++ - 如何从 C++ 中输入的输入中随机选择?
- python - 如何从这个 traccar 输出字典中打印单个项目?
- scala - GroupBy 并根据 Scala 中的另一个地图转换地图
- delphi - Delphi FMX (Android) - 如何在没有提取的情况下读取 zip 流中的文本文件?