二级联动
- 先写后台代码
- 连接前台
- 下载Element以及axios
- 布局
然后写我们的二级联动的方法
getOptionsA() {
this.$axios
.get('http://localhost:55629/api/GetClassifies?pid=0')
.then((res) => {
this.optionsA = res.data
})
},
getOptionsB(value) {
//给第一级ID 赋值
this.resetForm.CIdA = value[0]
this.$axios
.get(`http://localhost:55629/api/GetClassifies?pid=${value[0]}`)
.then((res) => {
this.optionsB = res.data
})
},
在页面中绑定对应的字段
<el-cascader-panel :options="optionsA"
:props="{ value: 'CId', label: 'CName' }"
ref="optA"
@change="getOptionsB"></el-cascader-panel>
在Element中,props可以用来接收,它的value属性绑定对应的主键ID,label属性绑定要显示的字段
完成



浙公网安备 33010602011771号