溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

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

發(fā)布時間:2020-08-23 06:27:06 來源:腳本之家 閱讀:204 作者:254980080 欄目:web開發(fā)

組件綁定事件時

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>

以上這篇淺談vue中組件綁定事件時是否加.native就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持億速云。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI