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

网站设计一般是什么专业代理加盟项目

网站设计一般是什么专业,代理加盟项目,微信 wordpress,seo的外链平台有哪些1、效果 是你要的效果#xff0c;咱们继续往下看#xff0c;搜索面板实现省市区下拉#xff0c;原本有antd的Cascader组件#xff0c;但是级联组件必须选到子节点#xff0c;不能只选省#xff0c;满足不了页面的需求 2、环境准备 1、react18 2、antd 4 3、功能实现 … 1、效果 是你要的效果咱们继续往下看搜索面板实现省市区下拉原本有antd的Cascader组件但是级联组件必须选到子节点不能只选省满足不了页面的需求 2、环境准备 1、react18 2、antd 4 3、功能实现 原理封装一个受控组件该组件就是两select基本组件 1、首先导入需要的组件 import { Select, Space, Tag } from antd; 2、定义2个状态变量来存储选中省和市的下拉枚举 const [firstOptions, setFirstOptions] useStateany([]);const [secondOptions, setSecondOptions] useStateany([]); 3、组件可接收的props子属性 如下 options: 省市级联数据 value: 已选中的值 widthslect框的宽度 firstPlaceholder 第一个select框的placeholdersecondPlaceholder第二个select框的placeholder onChange 选中的值发生变化时回调 4、创建handleFirstChange函数来处理第一个select框的change事件更新第二个select框的下拉项和值 // 第一个select生变化const handleFirstChange (data: any) {if (!isEmpty(data) data.value) {let insertIndex (options || []).findIndex((item: any) {return item?.value data?.value;});setSecondOptions(options?.[insertIndex]?.children || []);onChange({ first: [data] });} else {setSecondOptions([]);onChange(null);}}; 5、创建onSecondChange 函数来处理第二个select框的change事件将选中的值回传给父组件 // 第二个select发生变化const onSecondChange (data: any) {if (!isEmpty(value) value.first) {if (!isEmpty(data)) {onChange({...value,second: mode multiple ? (data || []).filter((item: any) !isNil(item?.label)) : [data],});} else {onChange({ first: value.first, second: null });}} else {onChange(null);}}; 6、最后使用2个select组件渲染并将选中状态和change事件绑定到对应的属性上 return (Space wrap{false} directionhorizontal size{12}SelectdefaultValue{firstOptions[0]}style{{ width: width }}onChange{handleFirstChange}placeholder{firstPlaceholder || 请选择}value{value?.first}options{firstOptions}labelInValueallowClear/Selectstyle{{ width: width }}value{value?.second || []}onChange{onSecondChange}placeholder{secondPlaceholder || 请选择}options{secondOptions}{...mode multiple ? { mode: multiple, maxTagCount: responsive, tagRender: tagRender } : {}}labelInValueallowClear//Space/ ) 7、完整代码如下 import { Select, Space, Tag } from antd; import clsx from clsx; import { isEmpty, isNil } from lodash; import { useEffect, useState } from react; import ./index.less;const MultipleCascaderSelect (props: any) {const {options,value,onChange,width 160,firstPlaceholder,secondPlaceholder,mode multiple} props;const [firstOptions, setFirstOptions] useStateany([]);const [secondOptions, setSecondOptions] useStateany();useEffect(() {setFirstOptions(options || []);if (Array.isArray(value?.first) value.first.length) {let findIndex (options || []).findIndex((item: any) {return item.value value.first?.[0].value;});setSecondOptions(options[findIndex]?.children || []);} else {setSecondOptions([]);}}, [options, value]);// 第一个select生变化const handleFirstChange (data: any) {if (!isEmpty(data) data.value) {let insertIndex (options || []).findIndex((item: any) {return item?.value data?.value;});setSecondOptions(options?.[insertIndex]?.children || []);onChange({ first: [data] });} else {setSecondOptions([]);onChange(null);}};// 第二个select发生变化const onSecondChange (data: any) {if (!isEmpty(value) value.first) {if (!isEmpty(data)) {onChange({...value,second: mode multiple ? (data || []).filter((item: any) !isNil(item?.label)) : [data],});} else {onChange({ first: value.first, second: null });}} else {onChange(null);}};const tagRender ({ label, closable, onClose }: any) {const isLongTag ${label}.length 4;return (Tagcolor{label.props?.color}closable{closable}onClose{onClose}className{clsx([text-sky-400 bg-sky-400/10 text-sm font-normal leading-5,// border border-solid border-sky-400/50,max-w-[110px] border-none,// whitespace-nowrap text-ellipsis overflow-hidden])}span{isLongTag ? ${label.slice(0, 4)}... : label}/span{/* {isLongTag ? (Tooltiptitle{label}key{label}rootClassName{clsx(toolTipCard)}placementtopspan{label.slice(0, 4)}.../span/Tooltip) : (span{label}/span)} */}/Tag);};return (Space wrap{false} directionhorizontal size{12}SelectdefaultValue{firstOptions[0]}style{{ width: width }}onChange{handleFirstChange}placeholder{firstPlaceholder || 请选择}value{value?.first}options{firstOptions}labelInValueallowClear/Selectstyle{{ width: width }}value{value?.second || []}onChange{onSecondChange}placeholder{secondPlaceholder || 请选择}options{secondOptions}{...mode multiple ? { mode: multiple, maxTagCount: responsive, tagRender: tagRender } : {}}labelInValueallowClear//Space/); };export default MultipleCascaderSelect;组件调用 MultipleCascaderSelectwidth{162}options{enumData|| []}firstPlaceholder请选择secondPlaceholder请选择/
http://www.zqtcl.cn/news/473856/

相关文章:

  • 苏州网站建设哪家便宜平谷手机网站设计
  • 建设项目一次公示网站嘉兴新站seo外包
  • 电子商务网站模板 html专业网站建设服务报价
  • 网页设计和网站建设的区别研发一款app要多少钱
  • seo网站建设方案建个企业网站需要多少钱
  • 搭建网站的软件网页动态设计
  • 好的界面建筑网站甘孜网站建设
  • 电子商务网站创建过程网站排名提升软件
  • 青岛企业如何建网站购买网站建站
  • 广东自考网站建设管理网站做ddns解析
  • 网站建设分类如何重启网站服务器
  • 新蒲建设集团网站怎么把源码做网站
  • 嘉兴建设局网站在线制作头像框
  • 苏州行业网站建设服务网页制作需要学什么技术
  • 二 网站建设的重要性东莞seo建站优化收费
  • 农业公司注册流程及费用快排seo排名软件
  • 响应式中文网站欣赏机wordpress
  • 如何建网站并做推广亚马逊网站怎么做推广
  • 做好网站建设总结免费开发app平台下载
  • 哈尔滨建站免费模板app网站开发要多少钱
  • 大连网站设计九首选仟亿科技怎么做百度网站会显示图片在旁边
  • 南京营销网站建设wordpress图片购买下载
  • 装修平台网站制作word模板
  • 网站建设捌金手指花总十软文写作技巧
  • 做网站优化有用吗网站开发包括什么软件
  • 在线音乐网站开发现状有什么网站接效果图做的
  • 网站开发自学难吗上海网站建设百度推广公司哪家好
  • 建设部网站官网四库一平台房地产网站大全
  • 做外贸如何建立网站微信信息流广告投放
  • 上海工程建设招投标网站开发购物网站描述