#vue#Use the Element input box, use the enter key to search or submit

search

If there is only one input box in the entire form, press enter to search

<el-input  @keyup.enter.native="toFilterData"  
    v-model="formInline.students_name" ></el-input>

At the same time, monitor whether there is an input value. In the methods, write the monitoring method. When the value in the v-model is obtained, press the Enter key. If you need to monitor spaces or other keys, replace them with other key values.

 // //查询 
    toFilterData() {
    // 当用户没有输入内容就按enter键时,就return,不做任何操作,不去搜索
        if(this.formInline.students_name === '') {
             return
        } else {
        // 请求查询接口,将列表展现出来
            this.getTabletsIndex();  
         }
     },

If vue+elementUI presses the Enter key in the input box, the page will still be refreshed; the cause of the problem: When there is only one input box in a form element, pressing the Enter key in the input box should submit the form. If you wish to prevent this default behavior, you can add @submit.native.prevent to the <el-form> tag.

<el-form  @submit.native.prevent></el-form>

submit 

After entering the password, press enter to log in successfully

Just add the following code to the input box and button

 <el-form-item prop="password">
     <el-input 
         ref="password" 
         v-model="loginForm.password" 
         :type="passwordType"
         placeholder="请输入密码" 
         tabindex="2" 
        @keyup.enter.native="handleLogin" />
</el-form-item>
<el-button  :loading="loading" @click.native.prevent="handleLogin" >登录</el-button>

Guess you like

Origin blog.csdn.net/ZHENGCHUNJUN/article/details/127300899
Recommended