我要这个
export default {
props: {
key: {
type: String,
required: true,
},
},
...
}
Run Code Online (Sandbox Code Playgroud)
但这会导致运行时错误:
[Vue warn]: "key" is a reserved attribute and cannot be used as component prop.
Run Code Online (Sandbox Code Playgroud)
编辑:
澄清一下:我希望保留属性“key”是必需的。这是因为我的组件依赖于“通过键更改强制重新创建组件”的技巧。(关联)
我知道我可以与这样的组件的父进行通信:
<container>
<child-component v-for="(thing, index) in things"
:key="index"
v-on:thingDidSomething="thingDidSomethingInParent(index)"
></child-component>
</container>
Run Code Online (Sandbox Code Playgroud)
但是,如果我想从thingDidSomething子方法中提供参数,该怎么办:
v-on:thingDidSomething="thingDidSomethingInParent"
Run Code Online (Sandbox Code Playgroud)
并提供索引(键).我可以访问子组件中的密钥吗?