[英]How to clear the select option on click to (x) button in Vue.js?
How do I create a function or button for a clear select option field?如何为清晰的 select 选项字段创建 function 或按钮? I try with
我试试
<input type="reset" value="x" />
but when I clear one field, all fields are cleared.但是当我清除一个字段时,所有字段都被清除。 I'm not sure if you need my code with basic select fields?
我不确定您是否需要我的带有基本 select 字段的代码? I accept in any way
我以任何方式接受
It can be solved manually using event handlers .它可以使用事件处理程序手动解决。 Do:
做:
<input value="x" @click="clearOneField" />
And in your methods hook inside script, implement your method:在脚本中的方法挂钩中,实现您的方法:
clearOneField() {
this.field = null;
}
Let's take this example.我们以这个例子为例。 You could do it using v-model:
您可以使用 v-model 来做到这一点:
<script src="https://unpkg.com/vue"></script>
<div id="app">
<p>{{ message }}</p>
<select v-model="select">
<option value="">None</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<button v-on:click="clear">x</button>
</div>
<script>
new Vue({
el: '#app',
data: {
selectvalue: ''
}
})
</script>
fiddle: https://jsfiddle.net/vpqnh9dt/小提琴: https : //jsfiddle.net/vpqnh9dt/
@option:deselecting="deselecting" @option:deselecting="取消选择"
add event deselecting添加事件取消选择
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.