<!-- Vue-事件(鼠標事件、點擊事件) -->
<DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Vue.js</title>
<link rel="stylesheet" href="style2.css">
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="vue-app">
<h1>Event</h1>
<button @click.once="add(1)">漲一歲</button><!--只能點擊一次-->
<button v-on:click="sub(1)">減一歲</button>
<button v-on:dblclick="add(10)">漲十歲</button>
<button v-on:dblclick="sub(10)">減十歲</button><!-- 雙擊事件-->
<p>My age is {{ age }}</p>
<div id="canvase" v-on:mousemove="updateXY">{{ x }},{{ y }}
<span id="stopmove" v-on:mousemove.stop.prevent> 數(shù)據(jù)停止</span>
</div>
<a v-on:click.prevent="alert()">百度</a><!--阻止默認事件-->
</div>
<script src="app2.js"></script>
</body>
</html>
//實例化vue對象
new Vue({
el:"#vue-app",
data:{
age:30,
x:0,
y:0
},
methods:{
add: function(int) {
this.age += int;
},
sub: function(int) {
this.age -= int;
},
updateXY: function(event){
// console.log(event);
this.x = event.offsetX;
this.y = event.offsetY;
},
alert: function(){
alert("hello world");
}
}
});
#canvase{
width:600px;
padding:100px 20px;
text-align: center;
border: 1px solid #333;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。