vue.js - Vuejs在v-model为空时隐藏一个div
问题描述
我有一个这样的选择下拉菜单。
<select v-model="selectedInjection">
<option v-for="(match,i) in haufigkeitMatches"
:key="i"
:value="match.value" >{{ match.name }}
</option>
</select>
我以这种方式呈现价值
<td v-if="selectedInjection">{{Math.round(selectedInjection)}</td>
The value of the {{Math.round(selectedInjection)}
changes when the select value changes and it's working fine. 但是当我不选择任何值时,{{Math.round(selectedInjection)}
除非我选择新值,否则会显示旧的选定值。How can I hid the {{Math.round(selectedInjection)}
when the select value is empty?
这是 Jsfiddle https://jsfiddle.net/ey3scra0/
解决方案
最好v-show
在您的 div 中使用:
<div class="hideResult" v-show="showSelectedInjection && selectedProduct != ''">
{{Math.round(selectedInjection)}}
</div>
然后在第二次选择时添加@change:
<select v-model="selectedInjection" @change="setShowSelectedInjection">
您还需要showSelectedInjection
使用方法添加额外的字段setShowSelectedInjection
并设置:showSelectedInjection
setSelectsToDefault
data:{
showSelectedInjection: false,
(...)
methods:{
setSelectsToDefault(){
this.selectedIeProKg = 0;
this.selectedPreisProIE = 0;
this.showSelectedInjection = this.haufigkeitMatches.map(h => h.value).includes(this.selectedInjection);
},
setShowSelectedInjection(){
this.showSelectedInjection = true;
}
这是一个工作示例:JSFiddle
推荐阅读
- python - 用 Z = 0 的黑线绘制 3d 图?
- google-colaboratory - Google Colaboratory 上的 Kitty 模式是什么
- sql - 根据条件查找Oracle SQL中的日期差异
- java - Java中使用信号量的循环线程
- assembly - 带有零块的机器代码上的 objdump 不显示所有字节?
- android - 如何修复 gradle.app 中的版本不兼容问题
- c# - RestSharp上传文件没有填充RAM
- python - 如何正确访问 mendeley API?我无法获取文件的 document_id
- html - Angular - 在 app-root 内延迟加载的 CSS
- android-studio - 我有这个对 api 的 POST 请求,但它崩溃了。我不确定如何让函数在后台而不是主线程中运行