一, 给 button 按钮绑定 @keyup.enter
- <div class="btn">
- <Button type="primary" @click="handleAddBook" @keyup.enter="handleAddBook">录入</Button>
- </div>
二, 浏览器 url:event.target.baseURI;
- created(){
- this.keyupEnter()
- },
- methods:{
- keyupEnter(){
- document.onkeydown = e =>{
- let body = document.getElementsByTagName('body')[0]
- if (e.keyCode === 13 && e.target.baseURI.match(/inputbook/) && e.target === body) {
- console.log('enter')
- this.handleAddBook()
- }
- }
- },
- handleAddBook(){
- if(this.validate()){
- this._printQrcode()
- }
- }
- }
来源: http://www.bubuko.com/infodetail-2767418.html