【发布时间】:2017-03-11 16:29:44
【问题描述】:
我是 vue.js 的新手,并试图为我的选择框创建一个组件。我很难通过父组件将默认值传递给选择。
现在我在父组件中有这个
<div class="row">
<div class="col-md-4">
<active-dropdown :selected='selected', :options = 'active_options', @update = 'update_selected'></active>
</div>
</div>
这里是下拉组件
Vue.component 'active-dropdown',
template: '#active-dropdown'
props: ['options', 'selected']
data: ->
selection: { active_eq: 1, text: 'Active', show: true }
methods:
notify_selection: ->
@.$emit('update', @.selection)
这是模板
<script id="active-dropdown" type="text/template">
<div class="form-group">
<label>Active</label>
<select class="form-control" v-model="selection" v-on:change="notify_selection">
<option v-bind:value="{ active_eq: option.value, text: option.text, show: true }" v-for="option in options">{{ option.text }}</option>
</select>
</div>
</script>
当我尝试使用 selected 的 props 作为选择模型时,vue 会警告我不能改变 props。我应该如何在不将模型更改为所选道具的情况下为选择设置默认值?
【问题讨论】:
标签: javascript components vue.js