vue.js - 单击主 div 时隐藏 div,但单击子 div、href、spans 等时不隐藏
问题描述
因此,当您单击蓝色内容时,我想隐藏它,但如果您单击子元素,例如 h2、a、p 等,则不会。这可能吗?
请看小提琴
html
<html>
<head></head>
<body>
<div id="app">
<div v-if="modal" id="content" @click="toggle">
<h3>
Name
</h3>
<span>
<a href="">Like this (don't close if clicked)</a>
</span>
</div>
<button @click="toggle">Toggle</button>
</div>
</body>
</html>
.js
new Vue({
el: '#app',
data: {
modal: true
},
methods: {
toggle: function( ){
this.modal = !this.modal
}
}
});
.css
a {
color: white
}
#content {
width: 300px;
height: 300px;
background: blue;
color: white;
}
小提琴:http: //jsfiddle.net/awu752mr/6/
解决方案
我相信这就是v-on:click.self
修饰符的作用。请参阅文档中的此处。
推荐阅读
- oracle - 如何为 Oracle 优化 Dockerfile?
- xilinx-ise - 如何为 Ubuntu 19.10 安装 Xilinx ISE 14.7
- java - Java查找不包含在对象列表中的对象
- windows - 理解 SYSTEM_POWER_INFORMATION 结构中的 MaxIdlenessAllowed 和 TimeRemaining
- c++ - 交换字符串(字符串下标超出范围错误)
- c - 文件锁定程序不锁定文件
- python - Python中的字符串插值已经包含大括号
- excel - excel VBA中的循环列引用以更改另一个工作表
- ruby - 字符串操作挑战
- javascript - 如何使用 webpack 从模板加载 VueJS 应用程序?