2017-06-13 47 views
1

我正在尋找的VueJS最佳實踐對於輸入元件,並在下面的代碼段開關元件之間同步:綁定開關和形式的輸入

<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

我該如何做到這一點?

回答

1

設置綁定到輸入的device屬性的觀察器。在觀察器中,您可以根據device字符串的長度設置值switches.device_switch字符串:

watch: { 
    device: function(value) { 
    this.switches.device_switch = value.length !== 0; 
    } 
}