elementui select多级联动
场景:有时候有a,b,c三个下拉选项,b依赖a的选择,c依赖b的选择。本文实现了两级联动,三级联动同理实现
选择脚本
export default {
data() {
return {
scriptConfigForm: {
project: '',
script: '',
appids: ''
},
type: false
}
watch: {
'scriptConfigForm.project'(e) {
if (this.changeFlag) {
this.scriptConfigForm.script = ''
}
if (e) {
this.scriptOptions.splice(0, this.scriptOptions.length)
this.fetchListScript(e)
}
}
},
methods:{
fetchListScript(projectId) {
fetchListScript(projectId).then(res => {
for (var script of res.data.content) {
this.scriptOptions.push({
value: script.id,
label: script.filename
})
}
})
},
handleChangeFlag(type) {
// select回调,判断当前下拉框是否展示
this.changeFlag = type
}
}
}
参考:
通过watch监控字段变化
https://blog.csdn.net/only_neo/article/details/82825182 【可实现】
通过change监控值变化
https://www.freesion.com/article/59681102408/ 【可实现】