關(guān)于element ui中el-cascader的使用方式
更新時間:2022年09月16日 09:58:17 作者:whittet.沉夢昂志
這篇文章主要介紹了關(guān)于element ui中el-cascader的使用方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
element ui中el-cascader使用
要想實現(xiàn)進(jìn)入頁面直接選中選擇器中的選項
例→

那v-model綁定的值必須是數(shù)組形式的!?。╡lement ui官方文檔中沒提到這一點好像,我也是試了很多次才發(fā)現(xiàn)的)
代碼
<el-form-item label="分類:" prop="region" class="region">
<div class="block">
<el-cascader
v-model="optionProps" //**重點**
:options="myOptions2"
:props="{ checkStrictly: true }"
@change="handleChange"
></el-cascader>
</div>
</el-form-item>
element中el-cascader使用及自定義key名
下面展示一些 內(nèi)聯(lián)代碼片。
el-cascader的通過改變值時,獲取當(dāng)前選中數(shù)據(jù)
根據(jù)接口返回數(shù)據(jù),靈活定義key名
// template中的應(yīng)用 options為數(shù)據(jù)
// 1.props="optionProps":props是框架屬性,optionProps為自定義data中的key
//2. ref="cascaderAddr" 自定義 用來 @change事件取值用
<template>
<el-cascader
v-model="ruleForm.address"
:options="options"
:props="optionProps"
clearable
ref="cascaderAddr"
@change="cascaderChange"
></el-cascader>
</template>
//定義符合自己數(shù)據(jù)的key值
<script>
data() {
return {
optionProps: {
value: "code",
label: "name",
children: "children",
},
}
},
methods: {
cascaderChange() {
console.log(
this.$refs["cascaderAddr"].getCheckedNodes()[0].pathLabels,
"選擇地址"
);
// this.$refs["cascaderAddr"].getCheckedNodes()//完整的數(shù)據(jù)
//this.$refs["cascaderAddr"].getCheckedNodes()[0].pathLabels//value的值
},
}
</script>
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue實現(xiàn)高德坐標(biāo)轉(zhuǎn)GPS坐標(biāo)功能的示例詳解
生活中常用的幾種坐標(biāo)有:WGS-84、GCJ-02與BD-09。本文將利用Vue實現(xiàn)高德坐標(biāo)轉(zhuǎn)GPS坐標(biāo)功能,即實現(xiàn)GCJ-02坐標(biāo)轉(zhuǎn)換成WGS-84坐標(biāo),需要的可以參考一下2022-04-04
SyntaxError:?/xx.vue:?Unexpected?token,?expected?“,“錯誤解
這篇文章主要為大家介紹了SyntaxError:?/xx.vue:?Unexpected?token,?expected?“,“錯誤解決方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08

