有这么一个需求,
假如有一个div
元素,点击他的时候他要触发他的点击事件之后再隐藏
如果点击了别的地方,那么他也要隐藏
需要用vue实现,大家有什么好的想法
有这么一个需求,
假如有一个div
元素,点击他的时候他要触发他的点击事件之后再隐藏
如果点击了别的地方,那么他也要隐藏
需要用vue实现,大家有什么好的想法
我猜测你大概是想实现个模态框吧。
<body>
<div id="app">
<div @click="btnShow = false" style="width: 100vw;height: 100vh; background-color: rgba(100,100,100,0.2);" v-show="btnShow">
<button @click.stop="doAndThenHide">点击</button>
</div>
</div>
<script>
let app = new Vue({
el: '#app',
data: {
btnShow: true
},
methods: {
doAndThenHide (ev){
console.log(ev.target.nodeName);
this.btnShow = false;
}
}
})
</script>
<template>
<div>
<el-button type="primary" v-if="buttonShow" @click="onClickButton1">button1</el-button>
<el-button type="primary" @click="buttonShow=false">click to hide button1</el-button>
</div>
</template>
<script>
export default {
data() {
return {
buttonShow: true
};
},
methods: {
onClickButton1() {
alert("button1 clicked");
}
}
};
</script>
6 回答3k 阅读✓ 已解决
9 回答3.1k 阅读
4 回答1.1k 阅读✓ 已解决
4 回答1.8k 阅读
6 回答875 阅读✓ 已解决
5 回答864 阅读✓ 已解决
4 回答1k 阅读✓ 已解决
我自己有个想法大概如下思路: