相关疑难解决方法(0)

如何将“key”指定为必需的道具?

我要这个

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”是必需的。这是因为我的组件依赖于“通过键更改强制重新创建组件”的技巧。(关联)

vue.js vuejs2

3
推荐指数
1
解决办法
4140
查看次数

VueJS通过v-for与父容器通信,提供索引和参数

我知道我可以与这样的组件的父进行通信:

<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)

提供索引(键).我可以访问子组件中的密钥吗?

vue.js

2
推荐指数
1
解决办法
200
查看次数

标签 统计

vue.js ×2

vuejs2 ×1