遞迴二級聯動前後臺使用方法
阿新 • • 發佈:2021-09-16
一、後臺程式碼
/// <summary> /// 遞迴 /// </summary> /// <param name="menus"></param> /// <param name="parentId"></param> /// <returns></returns> public List<TsMenu> GetMenu(List<Menu> menus,int parentId) {//Lamdba //商品管理 return menus.Where(u => u.ParentId == parentId).Select(m => new TsMenu() { MId = m.MId, MName = m.MName, Icon = m.Icon, Path = m.Path, ParentId= m.ParentId, TsMenus = GetMenu(menus,m.MId) //商品管理的ID }).ToList();
二、建立連結連結前臺下載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 }) },
四、在頁面中繫結對應的欄位註釋:在Element中,props可以用來接收,它的value屬性繫結對應的主鍵ID,label屬性繫結要顯示的欄位完成
<el-cascader-panel :options="optionsA" :props="{ value: 'CId', label: 'CName' }" ref="optA" @change="getOptionsB"></el-cascader-panel>
待續......