logologo

Element UI 使用碰到的一些问题

Apr 9, 2024 · 10 min

el-input 按回车后自动刷新页面

如题,后翻看文档原来是规范要求:

W3C 标准中有如下规定

When there is only one single-line text input field in a form,the user agent should accept Enter in that field as a request to submit the form。

即:当一个 form 元素中只有一个输入框时,在该输入框中按下回车应提交该表单。如果希望阻止这一默认行为,可以在 <el-form> 标签上添加 @submit.native.prevent

el-dialog 中的 el-form 重置无效

<el-dialog v-model:visible="show">
  <el-form v-model="form"/>
</el-dialog>

el-form 会以首次挂载后的状态作为初始默认值,因此我们在使用弹窗回显表单数据时,应该先显示出弹窗,然后在下一次事件循环再去做数据的回显:

function handleEdit(data) {
  this.show = true
  this.$nextTick(() => {
    this.form = data
  })
}