当前位置: 首页 > news >正文

el-cascader 使用笔记

1.效果

在这里插入图片描述

2.官网

https://element.eleme.cn/#/zh-CN/component/cascader

3.动态加载(官网)

<el-cascader :props="props"></el-cascader><script>let id = 0;export default {data() {return {props: {lazy: true,lazyLoad (node, resolve) {const { level } = node;setTimeout(() => {const nodes = Array.from({ length: level + 1 }).map(item => ({value: ++id,label: `选项${id}`,leaf: level >= 2}));// 通过调用resolve将子节点数据返回,通知组件数据加载完成resolve(nodes);}, 1000);}}};}};
</script>

在这里插入图片描述

4.使用实例

(1)页面

<el-form-item label="行政区划" prop="divisionCode"><el-cascader :props="props" v-model="form.divisionCode" style="width: 100%;"></el-cascader>
</el-form-item><script>export default {data() {return {props: {lazy: true,lazyLoad (node, resolve) {let value=node.value==undefined?"":node.value;findAll(value).then(res=>{const nodes=res.data;// 通过调用resolve将子节点数据返回,通知组件数据加载完成resolve(nodes);})}},};}};
</script>

(2)后端

/*** 查询行政区划列表*/
@GetMapping("/findAll")
public AjaxResult findAll(@RequestParam("code") String code) {List<DivisionVo> list = tDivisionService.selectDivisionList(code);return AjaxResult.success(list);
}@Data
public class DivisionVo {@Schema(description = "区划编码")private String value;@Schema(description = "区划名称")private String label;@Schema(description = "是否有下级:false=有,true=没有")private Boolean leaf;
}<select id="selectDivisionList" resultType="com.ruoyi.expertveteran.vo.DivisionVo">SELECT`code` VALUE,short_name label,leafFROMt_divisionWHERE<if test="code!=null and code!=''">parent_code =#{code}</if><if test="code==null or code==''">parent_code IS NULL</if>
</select>

5.使用实例(封装组件)

(1)组件 components下创建目录DivisionCascader,DivisionCascader下创建index.vue,代码如下

参考:https://blog.csdn.net/Binglianxiaojiao/article/details/143017798

<template><el-cascader :value="value" :props="props"  @change="handleChange" style="width: 100%;" clearable filterable placeholder="请选择行政区划"/>
</template><script>
import {findAll} from "@/api/expertveteran/division";export default {model: {prop: 'value',event: 'change'},props: {value: {type: Array,default: () => []}},data() {return {props: {lazy: true,lazyLoad (node, resolve) {let value=node.value==undefined?"":node.value;findAll(value).then(res=>{const nodes=res.data;// 通过调用resolve将子节点数据返回,通知组件数据加载完成resolve(nodes);})}},}},methods: {handleChange(val) {this.$emit('change', val);}}
}
</script>

(2)main.js

import DivisionCascader from "@/components/DivisionCascader"// 全局组件挂载
Vue.component('DivisionCascader', DivisionCascader)

(3)使用

<el-form-item label="行政区划" prop="divisionCode"><division-cascader v-model="form.divisionCode"/>
</el-form-item>

(4)其他相关

division.js

import request from '@/utils/request'// 查询行政区划列表
export function findAll(code) {return request({url: '/expertveteran/division/findAll?code='+code,method: 'get',})
}// 编码处理
export function handleCode(code) {if (Array.isArray(code)){return code[code.length-1]}if (code.length==6){return [code.substr(0,2),code.substr(0,4),code.substr(0,6)]}if (code.length==9){return [code.substr(0,2),code.substr(0,4),code.substr(0,6),code.substr(0,9)]}
}

编码处理

import {handleCode} from "@/api/expertveteran/division";
/** 修改按钮操作 */
handleUpdate(row) {this.reset();const id = row.id || this.idsgetExpertInfo(id).then(response => {this.form = response.data;this.form.divisionCode=handleCode(this.form.divisionCode);this.open = true;this.title = "修改专家信息";});
},
/** 提交按钮 */
submitForm() {this.$refs["form"].validate(valid => {if (valid) {this.form.divisionCode=handleCode(this.form.divisionCode)if (this.form.id != null) {updateExpertInfo(this.form).then(response => {this.$modal.msgSuccess("修改成功");this.open = false;this.getList();});} else {addExpertInfo(this.form).then(response => {this.$modal.msgSuccess("新增成功");this.open = false;this.getList();});}}});
},
http://www.lryc.cn/news/488227.html

相关文章:

  • 代替Spinnaker 的 POINTGREY工业级相机 FLIR相机 Python编程案例
  • 网络篇12 | SSH2协议应用,禁SFTP子模式实现文件传输
  • MetaGPT实现多动作Agent
  • docker更新镜像源
  • TSmaster Trace 窗口
  • 【Python模拟websocket登陆-拆包封包】
  • 速盾:海外服务器使用CDN加速有什么好处?
  • windows系统中实现对于appium的依赖搭建
  • 使用MATLAB进行字符串处理
  • Sourcetree登录GitLab账号
  • Linux进阶:软件安装、网络操作、端口、进程等
  • 光猫、路由器、交换机之连接使用(Connection and Usage of Optical Cats, Routers, and Switches)
  • 2025蓝桥杯(单片机)备赛--扩展外设之超声波测距原理与应用(十一)
  • 分布式数据库中间件可以用在哪些场景呢
  • MyBatis-Plus分页插件IPage用法
  • 使用MATLAB进行遗传算法设计
  • mindtorch study
  • java八股-SpringCloud微服务-Eureka理论
  • 2024信创数据库TOP30之蚂蚁集团OceanBase
  • 查找redis数据库的路径
  • DrugLLM——利用大规模语言模型通过 Few-Shot 生成生物制药小分子
  • 【蓝桥杯C/C++】翻转游戏:多种实现与解法解析
  • 【AI系统】核心计算之矩阵乘
  • Vue.js 自定义指令:从零开始创建自己的指令
  • 策略模式
  • 性能优化--CPU微架构
  • 在 Sanic 框架中实现高效内存缓存的多种方法
  • Mac 环境变量配置基础教程
  • Qt如何屏蔽工具栏(QToolBar)自动折叠功能
  • 【数据分享】中国统计摘要(1978-2024)