1、效果

2、参数
| 参数 | 说明 | 默认 |
|---|---|---|
| visible | 是否打开 | 默认false |
| dataSource | 数据源 | { label: ‘标签一’, id: 1 }, { label: ‘标签二’, id: 2 }, |
| currentId | 当前选增的标签id | 1 |
| classname | 样式类 | ‘ll’ |
| clickMastClose | 是否支持点击遮罩关闭 | false |
事件
| handleCancel | 点击取消触发的事件 |
|---|---|
| handleChoose | 切换标签的选中事件 |
3、使用
import ModalList from './components/ModalList'...components: {ModalList}...<modal-list:visible.sync="visible":dataSource="this.dataSource":currentId="this.currentId"@handleChoose="handleChoose"></modal-list>
4、组件源码
<template><div :class="classname" class="modal-list-wrapper" v-show="visible"><div class="mask" /><div class="list-wrapper" :class="visible ? 'active-entry' : 'active-out'"><ul class="list-ul"><liv-for="item in this.dataSource":key="item.id"class="list-li":style="currentId === item.id && 'color:#0082FF'"@click="handleChoose(item)">{{ item.label }}</li></ul><div class="cancel" @click="cancel">{{ cancelText }}</div></div></div></template><script>import Vue from 'vue';export default Vue.extend({name: 'ModalList',props: {classname: {default: 'll',type: String,},dataSource: {default: () => [{ label: '标签一', id: 1 },{ label: '标签二', id: 2 },],type: Array,},currentId: {default: 1,type: Number,},cancelText: {default: '取消',type: String,},visible: {type: Boolean,default: false,},},data() {return {};},watch: {},methods: {cancel: function () {this.$emit('update:visible', false);},handleChoose: function (item) {this.$emit('handleChoose', item);},open: function () {setTimeout(() => {this.visible = true;}, 1000);},},})</script><style lang="scss" scoped>.modal-list-wrapper {.mask {position: fixed;top: 0px;left: 0px;right: 0px;bottom: 0px;background-color: rgba(0, 0, 0, 0.6);z-index: 99;}.list-wrapper {position: fixed;bottom: -180px;width: 100%;z-index: 100;padding: 0px 8px;// transition: all 3s;box-sizing: border-box;.list-ul {width: 100%;max-height: 300px;overflow: auto;list-style: none;border-radius: 8px;.list-li {width: 100%;background: #fff;height: 56px;line-height: 56px;text-align: center;border-bottom: 1px solid #e5e5e5;&:last-of-type {border-bottom: none;}}}.cancel {border-radius: 8px;background: #fff;margin-top: 8px;height: 56px;line-height: 56px;text-align: center;}}.active-entry {animation: slideIn 0.3s ease forwards;}.active-out {animation: slideOut 0.3s ease forwards;}@keyframes slideIn {0% {transform translate3d(0, 0, 0);}100% {transform translate3d(0, -115%, 0);}}@keyframes slideOut {0% {transform translate3d(0, -115%, 0);}100% {transform translate3d(0, 0, 0);}}}</style>
