mounted() {
//父級下拉框 擴(kuò)大選擇區(qū)域
setInterval(function() {
document.querySelectorAll(".el-cascader-node__label").forEach(el => {
el.onclick = function() {
if (this.previousElementSibling) this.previousElementSibling.click();
};
});
}, 1000);
},
然后樣式做修改 --記得要全局改 不然改不動
.el-radio__input {
display: none;
}
例子:
<template>
<!-- 創(chuàng)建班級管理 -->
<d2-container class="majorCss">
<el-form label-position="right" label-width="6em" >
<el-form-item label="班級名稱">
<el-input v-model="createData.place_name" placeholder="請輸入班級名稱"></el-input>
</el-form-item>
<el-form-item label="父級" >
<el-cascader
:options="placeList"
:props="majorProps"
v-model="parentId"
:show-all-levels="false"
placeholder="請選擇父級"
></el-cascader>
</el-form-item>
<el-button
size="default"
@click="saveBtn"
type="primary"
class="button-login edit-loginBtn">
保存
</el-button>
</el-form>
</d2-container>
</template>
<script>
import { createSystemPlace, getPlacesList } from "@/api/sys.login";
import { mapState, mapActions } from "vuex";
export default {
name: "base-config-job-title-create",
computed: {
...mapState("d2admin/page", [
"current" //用戶獲取當(dāng)前頁面的地址庇楞,用于關(guān)閉
])
},
data() {
return {
parentId: [0], //父級默認(rèn)選項
//當(dāng)前新增信息
createData: {
place_name: "",
parent_id: 0,
},
placeList: [], //父級列表
majorProps: {
children: "_child",
label: "place_name",
value: "place",
checkStrictly: true
}
};
},
created() {
this.getplaceListData();
},
mounted() {
//父級下拉框 擴(kuò)大選擇區(qū)域
setInterval(function() {
document.querySelectorAll(".el-cascader-node__label").forEach(el => {
el.onclick = function() {
if (this.previousElementSibling) this.previousElementSibling.click();
};
});
}, 1000);
},
methods: {
...mapActions("d2admin/page", ["close"]),
//獲取父級列表
getplaceListData() {
getPlacesList().then(res => {
let data = {
place: 0,
place_name: "根級"
};
this.placeList = res;
this.placeList.unshift(data);
});
},
//保存
saveBtn() {
if (this.createData.place_name == "") {
this.$message.error("班級名稱不能為空");
return;
}
if (this.parentId.length > 1) {
let data = this.parentId.pop();
this.createData.parent_id = parseInt(data);
} else {
this.createData.parent_id = parseInt(this.parentId.join());
}
createSystemPlace(this.createData).then(res => {
this.$message({
message: "添加成功",
type: "success"
});
//這里需要關(guān)閉當(dāng)前tab頁
let tagName = this.current;
this.close({ tagName });
});
}
}
};
</script>
<style lang="scss">
.majorCss {
.el-input {
width: 316px;
}
.button-login {
margin-left: 86px;
}
}
.el-cascader-node {
.el-radio__input {
display: none ;
}
}
</style>
從網(wǎng)上找來的 非原創(chuàng)