業(yè)務(wù)需求
image.png
找了好多都沒有找到,想著自己寫一個(gè),有啥bug禾锤,歡迎大家指點(diǎn)改正(基于vue)
html
<el-cascader ref="cascader" v-model="filterAddress" @change="filterChange" :options="options"></el-cascader>
js
export default {
data() {
return {
filterAddress:null,
options: [{
value: 'zhinan',
label: '指南',
children: [{
value: 'shejiyuanze',
label: '設(shè)計(jì)原則',
children: [{
value: 'yizhi',
label: '一致'
}, {
value: 'fankui',
label: '反饋'
}, {
value: 'xiaolv',
label: '效率'
}, {
value: 'kekong',
label: '可控'
}]
}, {
value: 'daohang',
label: '導(dǎo)航',
children: [{
value: 'cexiangdaohang',
label: '側(cè)向?qū)Ш?
}, {
value: 'dingbudaohang',
label: '頂部導(dǎo)航'
}]
}]
}, {
value: 'zujian',
label: '組件',
children: [{
value: 'basic',
label: 'Basic',
children: [{
value: 'layout',
label: 'Layout 布局'
}, {
value: 'color',
label: 'Color 色彩'
}, {
value: 'typography',
label: 'Typography 字體'
}, {
value: 'icon',
label: 'Icon 圖標(biāo)'
}, {
value: 'button',
label: 'Button 按鈕'
}]
}, {
value: 'form',
label: 'Form',
children: [{
value: 'radio',
label: 'Radio 單選框'
}, {
value: 'checkbox',
label: 'Checkbox 多選框'
}, {
value: 'input',
label: 'Input 輸入框'
}, {
value: 'input-number',
label: 'InputNumber 計(jì)數(shù)器'
}, {
value: 'select',
label: 'Select 選擇器'
}, {
value: 'cascader',
label: 'Cascader 級(jí)聯(lián)選擇器'
}, {
value: 'switch',
label: 'Switch 開關(guān)'
}, {
value: 'slider',
label: 'Slider 滑塊'
}, {
value: 'time-picker',
label: 'TimePicker 時(shí)間選擇器'
}, {
value: 'date-picker',
label: 'DatePicker 日期選擇器'
}, {
value: 'datetime-picker',
label: 'DateTimePicker 日期時(shí)間選擇器'
}, {
value: 'upload',
label: 'Upload 上傳'
}, {
value: 'rate',
label: 'Rate 評(píng)分'
}, {
value: 'form',
label: 'Form 表單'
}]
}, {
value: 'data',
label: 'Data',
children: [{
value: 'table',
label: 'Table 表格'
}, {
value: 'tag',
label: 'Tag 標(biāo)簽'
}, {
value: 'progress',
label: 'Progress 進(jìn)度條'
}, {
value: 'tree',
label: 'Tree 樹形控件'
}, {
value: 'pagination',
label: 'Pagination 分頁'
}, {
value: 'badge',
label: 'Badge 標(biāo)記'
}]
}, {
value: 'notice',
label: 'Notice',
children: [{
value: 'alert',
label: 'Alert 警告'
}, {
value: 'loading',
label: 'Loading 加載'
}, {
value: 'message',
label: 'Message 消息提示'
}, {
value: 'message-box',
label: 'MessageBox 彈框'
}, {
value: 'notification',
label: 'Notification 通知'
}]
}, {
value: 'navigation',
label: 'Navigation',
children: [{
value: 'menu',
label: 'NavMenu 導(dǎo)航菜單'
}, {
value: 'tabs',
label: 'Tabs 標(biāo)簽頁'
}, {
value: 'breadcrumb',
label: 'Breadcrumb 面包屑'
}, {
value: 'dropdown',
label: 'Dropdown 下拉菜單'
}, {
value: 'steps',
label: 'Steps 步驟條'
}]
}, {
value: 'others',
label: 'Others',
children: [{
value: 'dialog',
label: 'Dialog 對話框'
}, {
value: 'tooltip',
label: 'Tooltip 文字提示'
}, {
value: 'popover',
label: 'Popover 彈出框'
}, {
value: 'card',
label: 'Card 卡片'
}, {
value: 'carousel',
label: 'Carousel 走馬燈'
}, {
value: 'collapse',
label: 'Collapse 折疊面板'
}]
}]
}, {
value: 'ziyuan',
label: '資源',
children: [{
value: 'axure',
label: 'Axure Components'
}, {
value: 'sketch',
label: 'Sketch Templates'
}, {
value: 'jiaohu',
label: '組件交互文檔'
}]
}]
};
},
mounted() {
// 將el-cascader中的input框顯示為div
let cascader = this.$refs.cascader;
cascader.$children[0].$refs.input.parentNode.innerHTML=`
<div class='cascader_div'>
<div class='display'>全部</div>
<i class="el-icon-arrow-down"></i>
</div>`;
},
methods: {
// el-cascader顯示數(shù)據(jù)
filterChange(){
// this.filterAddress?document.querySelector('.display').className='display beyond':document.querySelector('.display').className='display';
document.querySelector('.display').innerHTML=this.filterAddress;
},
},
};
css
/deep/ .el-input--suffix .cascader_div{
display: flex;
align-items: center;
>div{
font-size: 12px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #999999;
}
>i{
font-size: 12px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #999999;
margin-left: 3px;
}
}