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

江苏市场监督管理局app上海网站优化公司

江苏市场监督管理局app,上海网站优化公司,cms视频系统大全,呼和浩特网站建设公司el-cascader对于懒加载有支持方法&#xff0c;小难点在于回显的时候&#xff0c;由于懒加载第一次只有一层&#xff0c;所以要根据选中id数组一层层的加载。 子组件 <template><el-cascaderref"cascaderRef"v-model"selectedValue":props"…

el-cascader对于懒加载有支持方法,小难点在于回显的时候,由于懒加载第一次只有一层,所以要根据选中id数组一层层的加载。

子组件

<template><el-cascaderref="cascaderRef"v-model="selectedValue":props="CascaderProps":disabled="disabled"style="width: 500px"/>
</template>
  
<script setup>
import { ref, onMounted, defineEmits } from "vue";
import { ElCascader } from "element-plus";
import { listByParent, listParentByChild } from "@/api/common.js";
const cascaderRef = ref();
const props = defineProps({modelValue: [String, Number],disabled: {type: Boolean,default: false,},
});
const selectedValue = ref([]); // 选中的id数组const emit = defineEmits(["update"]); // 更新父组件的值
const CascaderProps = {lazy: true, // 懒加载checkStrictly: true, // 选择任意一项lazyLoad(node, resolve) {const { level, pathValues } = node;listByParent({adiId: node.value,}).then((res) => {const nodes = res.data.map((item) => {return {...item,label: item.name,value: item.adiId,leaf:(pathValues[0] == "330000000000" && level == 4) ||(pathValues[0] != "330000000000" && level == 2)? true: false, // 浙江地区层级和别的省层级不一样,true表示最后一层};});resolve(nodes);});},
};
// 回显逻辑
onMounted(async () => {selectedValue.value = []; // 重置setTimeout(async () => {// 延迟执行if (props.modelValue) {// 存在值let ids = await listParentByChild({type: 1,childAdiId: props.modelValue,}); // 获取父级id数组ids = ids.data.map((item) => item.adiId);selectedValue.value = ids.reverse(); // 调换顺序,省市区顺序await resolveCascaderNodes(selectedValue.value);}}, 1000);
});// 递归解析路径
const resolveCascaderNodes = async (ids) => {const nodes = [];let currentParent = "";// 加载子节点路径for (const id of ids) {const children = await listByParent(currentParent);const target = children.data.find((item) => item.id === id);if (target) {nodes.push(target);currentParent = id;}}return nodes;
};
// 监听值变化
watch(selectedValue, (val) => {if (val.length) emit("update", val[val.length - 1]);
});
</script>

父组件

                  <AreaCascader:key="new Date().getTime()":disabled="disabled":modelValue="form.concatAddress"@update="update"/>

key是为了每次使用都刷新,不加不会每次调用onMounted里的方法
form.concatAddress的值是最后一个区划id,在子组件里面要用接口获取到完整的id数组

import AreaCascader from "@/components/Cascader/index.vue";const update = (val) => {form.value.concatAddress = val;
};

记录一下

http://www.dtcms.com/wzjs/522261.html

相关文章:

  • 网站设计怎么用黑色网站推广平台
  • 自驾游网站建设广州网站推广软件
  • 小城市网站建设业务百度极速版客服电话
  • 有关做洁净工程的企业网站潍坊seo教程
  • 返利网站开发搜索引擎调词工具
  • wordpress快速仿站视频教程网络营销有哪些手段
  • 小程序搭建骗局厦门关键词seo排名网站
  • 购物商场网站开发过程详细说明站长工具忘忧草
  • 网站建设流量入口泰安做百度推广的公司
  • 中国最好的网站建设有哪些微信营销策略有哪些
  • 包头网站建设公司百度指数需求图谱
  • 龙华企业网站建设公司二十条优化措施全文
  • 品牌创意型网站开发facebook海外推广
  • 微博如何做外链到时自己网站seo关键词排名优化怎样收费
  • 做粘土网站拼多多代运营一般多少钱
  • 企业网站建设三个原则网站推广策划方案
  • 胶州网站搭建公司360搜索关键词优化软件
  • 自己黑自己做的网站优化关键词排名公司
  • 网站做优化得话从哪里优化株洲今日头条新闻
  • 浅析淘宝网站的建设与运营论文百度seo服务公司
  • 宁德营销型网站建设营销软件商城
  • 泰安房价各小区排行表seo关键词优化案例
  • 深圳网站建站建设百度竞价是什么工作
  • 建网站公司是如何赚钱找片子有什么好的关键词推荐
  • b2b电子商务网站设计对比进入百度网首页
  • iis7.5 查看网站流量seo排名点击软件推荐
  • 万网没备案怎么做网站2023第二波疫情已经到来了吗
  • 网站实名认证怎么做营销网站搭建
  • 益阳做网站电脑优化软件排行榜
  • 怎么给网站做防护seo基础培训教程