詳解vue-element Tree樹形控件填坑路
通過tree樹形控件的default-checked-keys屬性來設(shè)置默認選中的節(jié)點
html.vue
<el-form-item label="角色權(quán)限:"> <el-tree :data="data2" show-checkbox node-key="id" @check="handleNodeClick" :default-expanded-keys="[]" ref="tree" :default-checked-keys="default_select" :props="defaultProps"> </el-tree> </el-form-item>
html.js
data() {
return {
data2: [],
defaultProps: {
children: 'child',
label: 'name'
},
menu_ids: [],
// 默認選中
default_select: [],
role_id: 0,
}
},
methods: {
/**
* 獲取詳情
*/
getDetail() {
let that = this;
that.$http.post(that.adminApi.api_url + "/Role/show_edit", {
token: that.token,
role_id: that.role_id
}, {
emulateJSON: true
}).then(
function (res) {
var data = res.body;
if (data) {
that.ruleForm.name = data.name;
that.ruleForm.sort = data.sort;
that.ruleForm.status = data.status.toString();
/**重點開始*/
if(typeof (data.menu_id) == 'object'){
//轉(zhuǎn)數(shù)組
data.menu_id = Object.keys(data.menu_id).map(key=> data.menu_id[key]);
}
//賦值
data.menu_id.forEach((value)=>{
that.default_select.push(value);
});
setTimeout(function () {
that.default_select.forEach((value)=>{
that.$refs.tree.setChecked(value,true,false)
});
},100);
that.menu_ids = data.menu_id;
/**重點結(jié)束*/
}
});
},
/**
* 屬性控件
*/
handleNodeClick(e, data) {
console.log(data);
console.log(e);
this.menu_ids = data.checkedKeys
},
}
總結(jié),Tree樹形控件通過后臺接口獲取到數(shù)組數(shù)據(jù),還需要再次遍歷,將它再遍歷為數(shù)組,這樣我們才可以調(diào)用,如果直接從后臺獲取到數(shù)組來調(diào)用的時候,我們是獲取不到這個數(shù)組中的內(nèi)容。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
基于Vue實現(xiàn)圖片在指定區(qū)域內(nèi)移動的思路詳解
這篇文章主要介紹了基于Vue實現(xiàn)圖片在指定區(qū)域內(nèi)移動,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2018-11-11
Vue實現(xiàn)未登錄跳轉(zhuǎn)到登錄頁的示例代碼
本文主要介紹了Vue實現(xiàn)未登錄跳轉(zhuǎn)到登錄頁的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-08-08
關(guān)于vue中根據(jù)用戶權(quán)限動態(tài)添加路由的問題
每次路由發(fā)生變化時都需要調(diào)用一次路由守衛(wèi),并且store中的數(shù)據(jù)會在每次刷新的時候清空,因此需要判斷store中是否有添加的動態(tài)路由,本文給大家分享vue中根據(jù)用戶權(quán)限動態(tài)添加路由的問題,感興趣的朋友一起看看吧2021-11-11
KKFileView結(jié)合vue多格式文件在線預覽功能實現(xiàn)
kkFileView是git的開源在線文件預覽項目,這篇文章主要介紹了KKFileView結(jié)合vue多格式文件在線預覽功能,本文給大家介紹的非常詳細,需要的朋友可以參考下2024-02-02
基于Vue實現(xiàn)HTML轉(zhuǎn)PDF并導出
這篇文章主要為大家介紹了三種方法,可以實現(xiàn)將HTML頁面轉(zhuǎn)為PDF并實現(xiàn)下載。文中的示例代碼講解詳細,感興趣的小伙伴可以學習一下2022-04-04

