当使用vue的按键修饰符不起效果的时候怎么办?如@keyup.enter = '' ;

这个问题困扰了我一个多小时,各种测bug !始终测不出来! 

直接上代码(错误示范)

  <el-form-item prop="password">
        <el-input
           @keyup.enter="check('form')"  //在vue中这个代码是可行的
          type="password"
          v-model="form.password"
          placeholder="密码"
          prefix-icon="myicon myicon-key"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" class="login-button" @click="check('form')">登录</el-button>
      </el-form-item>

 

但是问题是:如果我们使用第三方组件这个方法并不奏效了 这时我们应该这么写  )

注意这是我们必须在@keyup.enter后面加一个native 来确保这个功能能够得到实现

  <el-form-item prop="password">
        <el-input
           @keyup.enter.native="check('form')"  
          type="password"
          v-model="form.password"
          placeholder="密码"
          prefix-icon="myicon myicon-key"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" class="login-button" @click="check('form')">登录</el-button>
      </el-form-item>

 

posted @ 2019-02-21 23:32  yaogengzhu  阅读(6042)  评论(3编辑  收藏  举报