vue事件绑定@click

vue事件绑定@click

事件绑定
1.Vue如果处理事件?

  • v-on指令用法
<input type= 'button' v-on:click = 'num++'/>
  • v-on简写形式
<input type = 'button' @click = 'num++' />

2.事件调用函数方式

  • 直接绑定函数名称
<button v-on:click='say'>Hellobutton>
  • 调用函数
<button v-on:click='say()'>Say hibutton>
DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Documenttitle>
    <script src = "js/vue.js">script>
head>
<body>
    <div id = "app">
        <div>{{num}}div>
        <button v-on:click = "num++">点击1button>
        <button @click = "num++">点击2button>
        <button @click = "handle">点击3button>
        <button @click = "handle()">点击4button>
    div>
    
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                num: '0'
            },
            methods:{
                handle:function(){
                    this.num++;
                }
            }
        })
    script>
body>
html>

你可能感兴趣的:(vue,vue.js,html,javascript)