【Vue】事件绑定

<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
<button v-on:click="sayHi">点击</button>
</div>

<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.min.js"></script>
<script>
    var vm = new Vue({
        el: "#app",
        data:{
            message:"hello Vue!"
        },
        methods:{//方法必须定义在Vue的methods对象中
            sayHi:function () {
                alert(this.message);
            }

        }
    });

</script>
</body>
</html>

  

posted @ 2020-12-07 22:17  Mr_sven  阅读(99)  评论(0编辑  收藏  举报