Skip to content

个人名片二维码 (xh-vcard-qrcode)

个人名片二维码组件是在基础二维码的基础上增加了个人信息展示功能,常用于个人联系信息分享。

基本用法

html
<xh-vcard-qrcode
  value="https://github.com/xiangheng08"
  avatar="/images/avatars/1.jpg"
  name="张三"
  description="前端工程师"
  tips="扫一扫二维码,加我为朋友。"
  shape="round"
  errorcorrectionlevel="H"
  logo="/images/vite.svg"
/>

属性 (Attributes)

除了基础二维码的所有属性外,还支持以下特有属性:

属性名类型默认值描述
widthnumber400名片宽度
paddingTopnumber0.135上内边距 (相对于宽度)
paddingBottomnumber0.125下内边距 (相对于宽度)
avatarstringundefined头像图片 URL
defaultAvatarstringundefined默认头像图片 URL
avatarSizenumber0.135头像大小 (相对于宽度)
avatarGapnumber0.03头像与名字的间隔 (相对于宽度)
avatarRadiusnumber0.1头像圆角 (相对于头像大小)
namestring''名字
nameFontstring'{0.048}px ...'名字字体
nameColorstring'#000000'名字颜色
nameGapnumber0.015名字与描述的间隔
descriptionstringundefined描述
descriptionFontstring'{0.03}px ...'描述字体
descriptionColorstring'#b4b4b4'描述颜色
tipsstring''提示语
tipsWidthnumber0.8提示语宽度 (相对于宽度)
tipsColorstring'#b4b4b4'提示语颜色
tipsFontstring'{0.03}px ...'提示语字体
qrcodeScalenumber0.725二维码所占比例 (相对于宽度)

示例

基本名片二维码

html
<xh-vcard-qrcode
  value="https://github.com/xiangheng08"
  name="张三"
  avatar="/images/avatars/1.jpg"
  description="前端工程师"
  tips="扫一扫上面的二维码图案,加我为朋友。"
/>

自定义样式

html
<xh-vcard-qrcode
  value="https://github.com/xiangheng08"
  name="张三"
  avatar="../images/avatars/1.jpg"
  description="资深前端工程师"
  tips="欢迎扫描二维码交流合作"
  width="375"
  nameColor="#333333"
  descriptionColor="#666666"
  tipsColor="#999999"
  color="#1296db"
  errorcorrectionlevel="H"
/>

不同头像样式

html
<!-- 圆形头像 -->
<xh-vcard-qrcode
  value="https://github.com/xiangheng08"
  name="张三"
  avatar="/images/avatars/1.jpg"
  avatarRadius="0.5"
/>

<!-- 方形头像 -->
<xh-vcard-qrcode
  value="https://github.com/xiangheng08"
  name="张三"
  avatar="/images/avatars/1.jpg"
  avatarRadius="0"
/>

注意事项

  1. 所有与宽度相关的属性都是相对值,实际像素值会根据 width 属性计算得出
  2. 字体属性中的 {数字} 会被替换为实际计算出的像素值
  3. 如果设置了 mask 属性,遮罩层会覆盖整个名片区域,而不仅仅是二维码区域