el-input-number默认值怎么设置
时间: 2023-09-13 08:13:17 浏览: 179
element input-number 默认值设置为空
el-input-number的默认值可以通过将v-model绑定的值设置为null或undefined来实现。例如,可以将v-model绑定的值设置为null来显示允许输入的最小值。在data中,可以将formData中对应的属性设置为null或undefined。例如:
```html
<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>
```
```javascript
data() {
return {
formData: {
idx: null,
winnersNum: null
}
}
}
```
另外,也可以将v-model绑定的值设置为undefined来实现默认值为空。例如:
```html
<el-input-number v-model="formData.idx" :precision="0" :step="1" :min="null" :max="100000"></el-input-number>
<el-input-number v-model="formData.winnersNum" :precision="0" :step="1" :min="null" :max="500"></el-input-number>
```
```javascript
data() {
return {
formData: {
idx: undefined,
winnersNum: undefined
}
}
}
```
这样设置后,el-input-number的默认值就会显示为允许输入的最小值,而不是空值。
#### 引用[.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^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [el-input-number 默认值设置失效](https://blog.csdn.net/hu961691590/article/details/119892713)[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^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文