Vue学习笔记
用于记录自我学习Vue的过程
前言
用于记录自我学习Vue的过程。
提示:以下是本篇文章正文内容,下面案例可供参考
一、学习内容
.stop
.self
.prevent
.once
二、案例实践
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<body>
<div id="vm">
<ul @click.self="ulClick()">
>
<li @click.stop="liClick">1</li>
<li @click.stop="liClick">2</li>
<li @click="liClick($event)">3</li>
<li @click="isShow = !isShow"><a @click.prevent="alertSth($event)" href="https://www.baidu.com">百度</a></li>
<li @click.self="isShow = !isShow"><a @click.prevent="alertSth($event)" href="https://www.baidu.com">百度</a></li>
<li @click="isShow = !isShow"><a @click.once="alertSth($event)" href="https://www.baidu.com">百度</a></li>
</ul>
<div v-show="isShow">我被显示和隐藏</div>
</div>
<script>
var vm = new Vue({
el: "#vm",
data: {
isShow: false
},
methods: {
liClick(ev) {
console.log("ev.target");
console.log(ev.target);
this.isShow = !this.isShow;
ev.stopPropagation();
},
ulClick() {
console.log("ulClick");
},
alertSth() {
alert("您点击了百度!");
console.log(112);
}
}
})
</script>
</body>
</html>
|