话不多说直接上代码
图例:
<template>
<div>
<el-cascader v-model="casValue" :props="{ multiple: true }" :options="options" @change="change" />
</div>
</template>
<script>
export default {
data() {
return {
casValue: [],
value: [],
shareScope: '-1',
options: [
{
value: 'zhinan',
label: '指南'
},
{
value: 'zujian',
label: '组件',
children: [
{
value: 'basic',
label: 'Basic'
},
{
value: 'form',
label: 'Form'
},
{
value: 'data',
label: 'Data'
},
{
value: 'notice',
label: 'Notice'
}
]
},
{
value: 'ziyuan',
label: '资源'
}
]
}
},
methods: {
change(val) {
for (var i = 0; i < val.length; i++) {
if (val[i][0] !== this.shareScope) {
this.shareScope = val[i][0]
break
}
}
const filterd = val.filter((v) => v[0] === this.shareScope)
this.casValue = []
this.casValue.push(...filterd)
}
}
}
</script>