首页 > 其他 > 详细

[Vue] Use basic event handling in Vue

时间:2017-01-19 21:18:02      阅读:215      评论:0      收藏:0      [点我收藏+]

Let‘s use a range of events and their modifiers to look at the cool ways we can deal with event handlers in Vue.

 

<template>
  <div>
    <button @mouseenter="counter += 1">Increment the counter!</button>
    <button @click="increment">Increment using a method!</button>
    <div v-text="counter"></div>
    <form @submit.prevent="logName">
      <input @keyup.ctrl.alt.shift.down="keyHandler" v-model="firstName" placeholder="First name..." />
    </form>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        counter: 0,
        firstName: ‘‘
      }
    },

    methods: {
      increment() {
        console.log(counter incremented!)
        this.counter += 1
      },

      logName() {
        console.log(firstName:, this.firstName)
      },

      keyHandler() {
        this.firstName = Evan
      }
    }
  }
</script>

 

  • Using ‘@‘ replace ‘v-on‘
  • @submit.prevent -> preventDefault
  • @submit.stop
  • @submit.once
  • @keyup.ctrl.alt.shift.down --> "ctrl + alt + shift + down" 4 keys click together

 

[Vue] Use basic event handling in Vue

原文:http://www.cnblogs.com/Answer1215/p/6308722.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!