vue中組件綁定事件時是否加.native


組件綁定事件時

1. 普通組件綁定事件不能添加.native, 添加后事件失效

2. 自定義組件綁定事件需要添加.native, 否則事件無效

<template>
  <!-- <mt-field label="用戶名" placeholder="請輸入用戶名"></mt-field> -->
  <input type="text" @keyup.native="show($event)">  //普通組件不能添加.native, 添加后事件失效
</template>

<script>
import { MessageBox } from 'mint-ui';

export default {
  name: 'about',
  data(){
    return{

    }
  },
  methods:{
    show(ev){
      MessageBox.alert('操作成功').then(action => {
        if(ev.keyCode==13){
          console.log('enter');
        }
      });
    }
  }
}
</script>

 

<template>
  <mt-field label="用戶名" placeholder="請輸入用戶名" @keyup.native="show($event)"></mt-field>  //自定義組件需要添加.native, 不添加事件無效
  <!-- <input type="text" @keyup.native="show($event)"> -->
</template>

<script>
import { MessageBox } from 'mint-ui';

export default {
  name: 'about',
  data(){
    return{

    }
  },
  methods:{
    show(ev){
      MessageBox.alert('操作成功').then(action => {
        if(ev.keyCode==13){
          console.log('enter');
        }
      });
    }
  }
}
</script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM