激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

node.js|vue.js|jquery|angularjs|React|json|js教程|

香港云服务器
服務(wù)器之家 - 編程語(yǔ)言 - JavaScript - 淺談Ant Design Pro 菜單自定義 icon

淺談Ant Design Pro 菜單自定義 icon

2021-11-22 16:35鈥碼狼酷 JavaScript

這篇文章主要介紹了Ant Design Pro 菜單自定義 icon,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

Ant Design Pro 官方文檔說(shuō)明 在菜單中使用自定義的 icon

由于 umi 的限制,在 router.config.js 是不能直接只是用組件的,Pro 中暫時(shí)支持 使用 ant.design 本身的 icon type,和傳入一個(gè) img 的 url。只需要直接在 icon 屬性上配置即可,如果是個(gè) url,Pro 會(huì)自動(dòng)處理為一個(gè) img 標(biāo)簽。

如果這樣還不能滿足需求,可以自定義 getIcon 方法。

如果你想使用 iconfont 的圖標(biāo),你可以使用ant.desgin的自定義圖標(biāo).

1. getIcon方法

  1. /* eslint no-useless-escape:0 */ 
  2. const reg = /(((^https?:(?://)?)(?:[-;:&=+$,w]+@)?[A-Za-z0-9.-]+(?::d+)?|(?:www.|[-;:&=+$,w]+@)[A-Za-z0-9.-]+)((?:/[+~%/.w-_]*)???(?:[-+=&;%@.w_]*)#?(?:[w]*))?)$/; 
  3. export function isUrl(path) { 
  4.  return reg.test(path); 
  5. import { isUrl } from '../utils/utils'
  6.   
  7. const getIcon = icon => { 
  8.  if (typeof icon === 'string') { 
  9.  if (isUrl(icon)) { 
  10.  return <Icon component={() => <img src={icon} alt="icon" className={styles.icon} />} />; 
  11.  } 
  12.  if (icon.startsWith('icon-')) { 
  13.  return <IconFont type={icon} />; 
  14.  } 
  15.  return <Icon type={icon} />; 
  16.  } 
  17.  return icon; 
  18. }; 

這個(gè)getIcon 來(lái)自于 AntD Pro 源代碼 getIcon 很全面,既可以用 Icon(使用AntD 提供的icon),又可以用 IconFont(使用www.iconfont.cn倉(cāng)庫(kù)的icon),還可以用靜態(tài)資源文件(<img src={....} /> 轉(zhuǎn)換成 icon);

實(shí)際項(xiàng)目中很多時(shí)候是需要替換成公司設(shè)計(jì)師設(shè)計(jì)的icon,因此我將他做了個(gè)簡(jiǎn)單的轉(zhuǎn)換

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const MenuIcon = ({imgStyle, imgSrc}) => (
 <Icon
 component={() => (
 <img
 style={{width: '1em', height: '1em', ...imgStyle}}
 src={imgSrc}
 alt="icon"
 />
 )}
 />
);
 
// example
// imgStyle 是由于UI切圖 尺寸經(jīng)常不夠準(zhǔn)確 img位置需要微調(diào)
const menuData = [
 {
 name: '首頁(yè)',
 icon: <MenuIcon imgSrc={require('../assets/menu.png')} imgStyle={{marginBottom: 5}} />,
 path: 'home',
 },
]

注意:img width height 設(shè)置為 1em ,讓它自適應(yīng)parent組件的大小,實(shí)現(xiàn)菜單打開/關(guān)閉時(shí),圖片的縮放,如果給具體數(shù)值則沒有縮放效果!??!

2. 使用ant.desgin的自定義圖標(biāo)(使用 svg).

利用 Icon 組件封裝一個(gè)可復(fù)用的自定義圖標(biāo)??梢酝ㄟ^(guò) component 屬性傳入一個(gè)組件來(lái)渲染最終的圖標(biāo),以滿足特定的需求。

代碼來(lái)自于 antd 官方文檔 icon 自定義圖標(biāo)

  1. import { Icon } from 'antd'
  2.   
  3. const HeartSvg = () => ( 
  4.  <svg width="1em" height="1em" fill="currentColor" viewBox="0 0 1024 1024"
  5.  <path d="M923 283.6c-13.4-31.1-32.6-58.9-56.9-82.8-24.3-23.8-52.5-42.4-84-55.5-32.5-13.5-66.9-20.3-102.4-20.3-49.3 0-97.4 13.5-139.2 39-10 6.1-19.5 12.8-28.5 20.1-9-7.3-18.5-14-28.5-20.1-41.8-25.5-89.9-39-139.2-39-35.5 0-69.9 6.8-102.4 20.3-31.4 13-59.7 31.7-84 55.5-24.4 23.9-43.5 51.7-56.9 82.8-13.9 32.3-21 66.6-21 101.9 0 33.3 6.8 68 20.3 103.3 11.3 29.5 27.5 60.1 48.2 91 32.8 48.9 77.9 99.9 133.9 151.6 92.8 85.7 184.7 144.9 188.6 147.3l23.7 15.2c10.5 6.7 24 6.7 34.5 0l23.7-15.2c3.9-2.5 95.7-61.6 188.6-147.3 56-51.7 101.1-102.7 133.9-151.6 20.7-30.9 37-61.5 48.2-91 13.5-35.3 20.3-70 20.3-103.3 0.1-35.3-7-69.6-20.9-101.9z" /> 
  6.  </svg> 
  7. ); 
  8.   
  9. const PandaSvg = () => ( 
  10.  <svg viewBox="0 0 1024 1024" width="1em" height="1em" fill="currentColor"
  11.  <path 
  12.  d="M99.096 315.634s-82.58-64.032-82.58-132.13c0-66.064 33.032-165.162 148.646-148.646 83.37 11.91 99.096 165.162 99.096 165.162l-165.162 115.614zM924.906 315.634s82.58-64.032 82.58-132.13c0-66.064-33.032-165.162-148.646-148.646-83.37 11.91-99.096 165.162-99.096 165.162l165.162 115.614z" 
  13.  fill="#6B676E" 
  14.  p-id="1143" 
  15.  /> 
  16.  <path 
  17.  d="M1024 561.548c0 264.526-229.23 429.42-512.002 429.42S0 826.076 0 561.548 283.96 66.064 512.002 66.064 1024 297.022 1024 561.548z" 
  18.  fill="#FFEBD2" 
  19.  p-id="1144" 
  20.  /> 
  21.  <path 
  22.  d="M330.324 842.126c0 82.096 81.34 148.646 181.678 148.646s181.678-66.55 181.678-148.646H330.324z" 
  23.  fill="#E9D7C3" 
  24.  p-id="1145" 
  25.  /> 
  26.  <path 
  27.  d="M644.13 611.098C594.582 528.516 561.55 512 512.002 512c-49.548 0-82.58 16.516-132.13 99.096-42.488 70.814-78.73 211.264-49.548 247.742 66.064 82.58 165.162 33.032 181.678 33.032 16.516 0 115.614 49.548 181.678-33.032 29.18-36.476-7.064-176.93-49.55-247.74z" 
  28.  fill="#FFFFFF" 
  29.  p-id="1146" 
  30.  /> 
  31.  <path 
  32.  d="M611.098 495.484c0-45.608 36.974-82.58 82.58-82.58 49.548 0 198.194 99.098 198.194 165.162s-79.934 144.904-148.646 99.096c-49.548-33.032-132.128-148.646-132.128-181.678zM412.904 495.484c0-45.608-36.974-82.58-82.58-82.58-49.548 0-198.194 99.098-198.194 165.162s79.934 144.904 148.646 99.096c49.548-33.032 132.128-148.646 132.128-181.678z" 
  33.  fill="#6B676E" 
  34.  p-id="1147" 
  35.  /> 
  36.  <path 
  37.  d="M512.002 726.622c-30.06 0-115.614 5.668-115.614 33.032 0 49.638 105.484 85.24 115.614 82.58 10.128 2.66 115.614-32.944 115.614-82.58-0.002-27.366-85.556-33.032-115.614-33.032z" 
  38.  fill="#464655" 
  39.  p-id="1148" 
  40.  /> 
  41.  <path 
  42.  d="M330.324 495.484m-33.032 0a33.032 33.032 0 1 0 66.064 0 33.032 33.032 0 1 0-66.064 0Z" 
  43.  fill="#464655" 
  44.  p-id="1149" 
  45.  /> 
  46.  <path 
  47.  d="M693.678 495.484m-33.032 0a33.032 33.032 0 1 0 66.064 0 33.032 33.032 0 1 0-66.064 0Z" 
  48.  fill="#464655" 
  49.  p-id="1150" 
  50.  /> 
  51.  </svg> 
  52. ); 
  53.   
  54. const HeartIcon = props => <Icon component={HeartSvg} {...props} />; 
  55. const PandaIcon = props => <Icon component={PandaSvg} {...props} />; 
  56.   
  57. ReactDOM.render( 
  58.  <div className="custom-icons-list"
  59.  <HeartIcon style={{ color: 'hotpink' }} /> 
  60.  <PandaIcon style={{ fontSize: '32px' }} /> 
  61.  </div>, 
  62.  mountNode, 
  63. ); 

補(bǔ)充知識(shí):Ant Design Pro Of Vue 項(xiàng)目中路由菜單icon 修改或新增

在 config / router.config.js 中修改,直接從 ant-design-vue-icon 取,只要 icon 組件的 type 值即可。

如:

<a-icon type="user" />

淺談Ant Design Pro 菜單自定義 icon

以上這篇Ant Design Pro 菜單自定義 icon就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://blog.csdn.net/xhwnous/article/details/90478979

延伸 · 閱讀

精彩推薦
1536
主站蜘蛛池模板: 国产乱淫av | 免费国产在线精品 | 久久久久久久久久网 | 免费网站看v片在线a | 成人激情在线 | 黄色网战入口 | 91视频观看| 久久人人做| 麻豆视频在线免费观看 | 国产wwww | 久久男人视频 | 久久精品国产99国产精品澳门 | 国产一区二区久久精品 | 日韩一级电影在线观看 | 欧美激情精品久久久久久久久久 | 国产亚洲精品久久久久久网站 | 毛片视频免费观看 | 99亚洲| 国产高潮好爽好大受不了了 | 欧美黄色免费视频 | 日本欧美中文字幕 | 成品片a免人视频 | 欧美一区二区精品夜夜嗨 | 国产乱子视频 | 56av国产精品久久久久久久 | av手机免费在线观看 | 欧美一级黄色网 | 叉逼视频 | 91快色| 国产精品999在线 | 国产羞羞视频免费在线观看 | 午夜精品老牛av一区二区三区 | 国产自在自线午夜精品视频在 | 色人久久 | 久国久产久精永久网页 | 欧美日韩精品一区二区三区在线观看 | 免费网址黄 | 国产午夜亚洲精品理论片大丰影院 | 亚洲伊人色欲综合网 | 一级做a爱视频 | 成人aaaaa片毛片按摩 |