Element UI 中el-input 框回车触发页面刷新问题及解决方案

问题描述:
输入框中按回车按钮,页面重新刷新

问题原因:
当 el-form 内只有一个 el-input 时,在输入框内回车就会触发表单提交的默认事件

解决方案:
在el-form中加@submit.native.prevent阻止这一默认行为
其中.native 表示对一个组件绑定系统原生事件 .prevent 表示提交以后不刷新页面
例如:

	`<el-form
        label-width="100px"
        label-position="right"
        v-if="mode.dialogVisible"
        @submit.native.prevent
      >
          <el-row type="flex">
              <el-col :span="12">
                <!-- 员工姓名 -->
                <el-form-item label="员工姓名">
                  <el-input
                    v-model="conditions.data.empName"
                    type="text"
                    clearable
                  ></el-input>
                </el-form-item>
              </el-col>
          </el-row>
      </el-form>`

猜你喜欢

转载自blog.csdn.net/qq_40896145/article/details/122885227