Javascript 如何在 vue.js 中使用 onfocusout 功能?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/49974289/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use onfocusout function in vue.js?
提问by dexter
I want to call a function as soon as the cursor moves from one text box to next. The function call should be made when a tab is clicked or after the expected entries are entered and moved to next.
我想在光标从一个文本框移动到下一个时立即调用一个函数。应在单击选项卡时或在输入预期条目并移至下一个后进行函数调用。
回答by tony19
You're seeking the blurevent, which occurs when the <input>loses focus. Use Vue syntaxto add a blur-event listener on the <input>:
您正在寻找blur当<input>失去焦点时发生的事件。使用Vue 语法在 上添加blur-event 侦听器<input>:
v-on:EVENT_NAME="METHOD"
Example:
例子:
<input v-on:blur="handleBlur">
Or shorter syntax:
或更短的语法:
@EVENT_NAME="METHOD"
Example:
例子:
<input @blur="handleBlur">
new Vue({
  el: '#app',
  methods: {
    handleBlur(e) {
      console.log('blur', e.target.placeholder)
    }
  }
})
<script src="https://unpkg.com/[email protected]/dist/vue.min.js"></script>
<div id="app">
  <input @blur="handleBlur" placeholder="first name">
  <input @blur="handleBlur" placeholder="last name">
</div>

