組件綁定事件時
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>