VUE:Select2
2024-09-05 06:59:50
<template>
<div>
<ul class="skill">
<li v-for='item of list' v-on:click='selectLi(item)'>{{item}}</li>
</ul>
</div>
</template> <script>
export default {
name:'myul',
props: ['list'],
methods: {
selectLi: function(item) {
//$emit触发当前实例上的自定义事件 receive
this.$emit('receive', item);
}
}
}
</script>
<style>
ul, li {
margin: 0;
padding: 0;
list-style: none;
}
.skill li {
font-size: 18px;
line-height: 2rem;
height: 2rem;
padding-left: 5px;
cursor: pointer;
}
.skill li:hover {
background-color: #008b45;
}
</style>
<template>
<div>
<div id="selectWrap">
<div class="searchBox">
<input type="text" :value="selectVal" @click='ulShow = !ulShow'/>
<a href="#" rel="external nofollow" class="search" v-text='btnName'></a>
</div>
<div>
<myul v-show='ulShow' v-bind:list='list' v-on:receive='changeVal'></myul>
</div>
</div>
</template> <script>
import Vue from 'vue'
import myul from './myul'
Vue.component("myul", myul)
export default {
name:'myselect',
data() {
return {
ulShow: false, //默认ul不显示,单击input改变ul的显示状态
selectVal: '' //选项值,input的值与选项值动态绑定
}
},
props: ['btnName', 'list'],
methods: {
changeVal(value) {
this.selectVal = value
}
}
}
</script>
<style>
#selectWrap {
width: 250px;
padding: 2rem;
background: #4682b4;
}
.searchBox input, .searchBox a {
line-height: 1.5rem;
height: 1.5rem;
margin-bottom: 1rem;
padding: 0 5px;
vertical-align: middle;
border: 1px solid #aaa;
border-radius: 5px;
outline: none;
}
.searchBox a {
display: inline-block;
text-decoration: none;
background-color: #b1d85c;
}
</style>
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import myselect from './myselect' Vue.config.productionTip = false /* eslint-disable no-new */
new Vue({
el: '#app',
data: {
data1: ['CSS', 'HTML', 'JavaScript']
},
components: {myselect},
template: "<myselect btn-name='search' v-bind:list='data1' style='float: left;margin-right: 2rem;'></myselect>" })
最新文章
- “Operation is not valid due to the current state of the object.”
- Linux下Nano命令使用指南
- Yii2 中自定义实例名称
- Linux下C++静态库、动态库的制作与使用
- Deep Learning(1)-Introduction学习总结
- 【mysql】关于innodb_file_format
- PHP 冒泡原理
- java 类型转json格式
- [转]后缀自动机(SAM)
- 【Unity3D】Unity自带组件—完成第一人称人物控制
- iOS iTunes文件共享
- IBUS-WARNING **: Process Key Event failed: Timeout was reached
- Dom学习笔记-(一)
- 使用ssh远程执行命令批量导出数据库到本地
- 在win下,如何用bat看程序运行的时间
- maven 项目快速下载jar方式
- Java 多重catch语句的具体使用介绍
- [No000014F]计算机编程语言家族史
- 透过CAT,来看分布式实时监控系统的设计与实现
- BZOJ 2440 [中山市选2011]完全平方数 (二分 + 莫比乌斯函数)