首页 > 其他分享 >v-on

v-on

时间:2022-11-26 21:12:31浏览次数:27  
标签: function xxp el am words data

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'
        }
    }
})

 

标签:,function,xxp,el,am,words,data
From: https://www.cnblogs.com/daxiangcai/p/16928294.html

相关文章