为页面元素绑定各种事件   (keydown keup click dbclick load etd)

 

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<script src="https://unpkg.com/vue/dist/vue.js"></script>

<title>Document</title>

</head>

<body>

 

<div id = "myApp">

<p>您最喜欢的游戏是:{{game}}</p>

<button v-on:click="btnClick('我的世界')">我的世界</button>

<button v-on:Click="btnClick('穿越火线')">穿越火线</button>

<button v-on:Click="btnClick('角地求生')">绝地求生</button>

<button @click="btnClick('斗地主')">斗地主</button>

<button @click="btnClick('恰代码')">恰代码</button>

</div>

 

<script>

var myApp = new Vue({

el:"#myApp",

data:{

game:'英雄联盟'

},

methods:{

btnClick:function(pname){

this.game = pname;

},

},

});

</script>

 

</body>

</html>

Logo

前往低代码交流专区

更多推荐