我正在寻找VueJS最佳实践,以便在以下代码段中同步输入元素和switch元素:
<div class="filter panel">
<div class="field_title">Device</div>
<el-switch v-model="switches.device_switch" name="device"></el-switch>
<b-form-input v-model="device" placeholder="Device"></b-form-input>
</div>
如果输入字段包含我想将v-model="switches.device_switch"
设置为true
的任何文字。
我怎样才能做到这一点?
答案 0 :(得分:1)
为绑定到输入的device
属性设置观察程序。在观察者中,您可以根据switches.device_switch
字符串的长度设置device
的值:
watch: {
device: function(value) {
this.switches.device_switch = value.length !== 0;
}
}