我在网上找不到任何文档或示例,但是将多个 Prop 传递给组件的正确方法是什么?
这是我尝试过的:
在 HTML
<component:prop1="data1" :prop2="data2"></component>
在 component.js
props: ['prop1','prop2'],
但显然不起作用......
最佳答案
尽管这有点旧,但我想做出贡献。
如果你想“一次”传递一堆属性,你可以使用“v-bind”
假设您的组件有一堆 Prop :
props: ['age', 'year', 'date']
取而代之的是下面的常规方式:
<MyAwesomeComponent :age="age" :year='year' :date='today' />
也可以这样做:
<MyAwesomeComponent v-bind="groupedProps" />
被“groupedProps”以下对象:
groupedProps: {age:134, year:2153, today: new Date()}
...v-bind="groupedProps"...
vue 文档 here 中描述了该行为
关于vuejs2 - Vue2 : is possible to pass multiple props to component?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45729208/