我是VueJS的新手.在react中,您可以轻松使用rest参数向 children 传递props .Vue中有类似的模式吗?
考虑具有几个子组件的父组件:
<template>
<header class="primary-nav">
<search-bar :config="searchBar"><search-bar>
// ^^^^ this becomes the key on the props for SearchBar
header>
</template>
export default {
data(){
return {
... a few components ...
searchBar : {
model: '',
name: 'search-bar',
placeholder: 'Search Away',
required:true,
another: true
andanother: true,
andonemoreanotherone:true,
thiscouldbehundredsofprops:true
}
}
}
}
<template>
<div :class="name">
<form action="/s" method="post">
<input type="checkbox">
<label :for="config.name" class="icon-search">{{config.label}}</label>
<text-input :config="computedTextInputProps"></text-input>
//^^^^ and so on. I don't like this config-dot property structure.
</form>
</div>
</template>
export default {
props: {
name: String,
required: Boolean,
placeholder: String,
model: String,
},
computed: {
computedtextInputProps(){
return justThePropsNeededForTheTextInput
}
}
...
我不喜欢的是props 是用config
键或任何其他任意键命名的.文本输入组件(未显示)是一个美化的input
字段,可以具有多个属性.我可以在创建组件时展平props ,但这通常是个好主意吗?
我很惊讶以前没人问过这个问题.
谢谢
Edit: 10-06-2017