v-on

v-on 可以为元素绑定事件
<body>
    <script src="../vue.js"></script>
    <div id="mydiv">
        <!-- 两种写法均可 -->
        <input type="button" value="my button" v-on:click="say">
        <input type="button" value="your button" @click="say">
        <input type="button" value="his button" @dblclick="say">
        <input type="button" value="change the text" @click="change">
        <div>{{ words  }}</div>

    </div>
    <script src="work2.js"></script>
</body>
var app = new Vue({
    el:'#mydiv',
    data:{
        words:'I am xxp'
    },
    methods: {
        say:function(){
            console.log('I LOVE YOU')
        },
        change:function(){
            // 注意不是 this.data.words
            this.words = 'I am not xxp'
        }
    }
})

 

posted @ 2022-11-26 20:57  树叶本子  阅读(55)  评论(0)    收藏  举报