Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

javascript - How to use onfocusout function in vue.js?

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.

question from:https://stackoverflow.com/questions/49974289/how-to-use-onfocusout-function-in-vue-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You're seeking the blur event, which occurs when the <input> loses focus. Use Vue syntax to add a blur-event listener on the <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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...