<template>
<div class="selectBox" style="padding:50px">
<input type="text" v-model="inputValue" @click.stop="showActive" />
<ul class="list" v-show="isShow">
<li
:class="isActive == index ? 'blue' : ''"
@click="clickName(item, index)"
v-for="(item, index) in list"
:key="index"
>
{{ item }}
</li>
</ul>
</div>
</template>
<script>
export default {
name: "Home",
data() {
return {
isActive: -1, //,选中颜色
inputValue: "",
isShow: false,
list: ["jack", "lucy", "Tom"],
};
},
mounted() {
let that = this;
//点击页面空白处隐藏下拉列表
document.addEventListener("click", function() {
that.isShow = false;
});
},
components: {},
methods: {
clickName(name, index) {
new Promise((resolve, reject) => {
this.inputValue = name;
this.isActive = index;
resolve("success");
}).then((resolve) => {
this.showNone();
});
},
showActive() {
this.isShow = true;
},
showNone() {
this.isShow = false;
},
},
};
</script>
<style scoped>
.blue {
background: #dae8fd;
font-weight: 700;
}
.list li {
cursor: pointer;
font-size: 20px;
line-height: 26px;
padding-left: 10px;
}
</style>
vue实现自定义下拉菜单
最新推荐文章于 2022-08-08 14:18:18 发布