Vue 学习笔记4 v-on

v-on

为元素绑定事件

<input type="button" value="按我1" v-on:click="func1()" />

可以用 [@] 代替 [v-on]

<input type="button" value="按我2" @click="func2()" />

常用事件列表

  • click 单击元素
  • mouseenter 鼠标进入元素

完整代码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Lesson 4 v-on</title>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.js"></script>
</head>

<body>
    <div id="app">
        <p>{{ message }}</p>
        <p><input type="button" value="按我1" v-on:click="func1()" /></p>
        <p><input type="button" value="按我2" @click="func2()" /></p>
    </div>
    <script>
        let tmp = new Vue({
            el: "#app",
            data: {
                "message": "Hello Vue",
            },
            methods: {
                "func1": function () {
                    this.message = "按钮1被按了"
                },
                "func2": function () {
                    this.message = "按钮2被按了"
                },
            }
        })
    </script>
</body>

</html>
posted @ 2020-08-24 16:24  太晓  阅读(157)  评论(0编辑  收藏  举报