el-input-number默认值为空
时间: 2023-09-14 21:12:37 浏览: 272
el-input-number的默认值为空的方法有多种。其中一种方法是将v-model设为null或空字符串。例如,在el-input-number的v-model属性中,将formData的对应字段设为null或'',如下所示:
```
<el-input-number v-model="formData.idx" :precision="0" :step="1" :min="1" :max="100000"></el-input-number>
<el-input-number v-model="formData.winnersNum" :precision="0" :step="1" :min="1" :max="500"></el-input-number>
data() {
return {
formData: {
idx: null,
winnersNum: ''
}
}
}
```
另外一种方法是对element input-number的源码进行兼容处理。在这种情况下,当值传入为''时,默认显示为空而非0。具体的解决方法是将v-model设为undefined,如下所示:
```
data() {
return {
formData: {
idx: undefined,
winnersNum: undefined
}
}
}
```
以上两种方法都可以实现el-input-number的默认值为空。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [element-ui 的 el-input-number的默认值设置为空](https://blog.csdn.net/HH18700418030/article/details/128466407)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [element input-number 默认值设置为空](https://download.csdn.net/download/qq_34086049/15483108)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文