下拉框-vue.gif
2.实现原理
mounted:初始化页⾯完成后,再对html的dom节点进⾏⼀些需要的操作组件
添加点击事件监听document.addEventListener,假设点击区域不再该区域上,关闭弹框3.实现代码
<script>
import DropSelet from "./components/dropSelet.vue"; export default {
name: "dropItem",
components: {
DropSelet,
},
data() {
return {
current_month: "All",
show_month: false,
month_list: [
{
name: "All",
},
{
name: "2022-1",
},
{
name: "2022-2",
},
],
};
},
mounted() {
document.addEventListener(
"click",
(e) => {
let s1 = this.$refs.s1;
if (!s1.contains(e.target)) {
this.show_month = false;
}
},
true
);
},
methods: {
choseItem(e) {
this.current_month = e.name;
this.show_month = false;
box sizing},
},
};
</script>
<style lang="less" scoped>
.drop_hd_ative {
background-color: pink;
color: #fff !important;
}
.drop_hd_item {
line-height: 30px;
color: #333;
}
.drop_hd {
position: absolute;
width: 200px;
min-height: 30px;
box-sizing: border-box;
padding: 10px;
background: #fff;
left: 0;
top: 3px;
border-radius: 5px;
z-index: 99;
box-shadow: 5px 5px 5px #ccc;
cursor: pointer;
}
.hd_e {

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。