1.4.5 • Published 5 years ago

vue-image-pro v1.4.5

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

vue-image-pro

Build Status license npm size download codecov

English Document

English Document

介绍

组件的灵感来源于小程序的 image 组件vue-avatar 组件, 相当于同时拥有两者的特性, 实现了包括图片自适应、响应式、当无图片时显示文字等。

应用场景

典型的应用场景就是头像, 当有图片是显示图片, 当无图片时显示用户名

相对于 vue-avatar 的改进

  • 对中文友好
  • 当图片宽高不一致时, 依然可以完美显示, 不会变形

文档和示例

文档点我查看 在线示例点我查看

Installation 安装

npm install vue-image-pro  --save

Usage 用法

// 全局 (推荐)
import ImagePro from 'vue-image-pro'

// 可以配置全局默认值
Vue.use(ImagePro, {
  src: '',
  color: '',
  username: '',
  backgroundColor: '',
  size: '',
  width: '',
  height: '',
  radius: '',
  mode: ''
})
// 局部导入
// 这里注意要有 {} 括号
import { ImagePro } from 'vue-image-pro'

export default {
  ...
  components: {
    ImagePro
  },
  ...
}
<image-pro :size="100" username="vue-image-pro" background-color="#123456" />

Props

属性名是否必填默认值类型说明
usernameN(空字符)String当 src 为空时,显示计算后用户名
srcN-String图片链接
defaultSrcN-String默认图片
modeNaspectFillString图片展示模式(下有详细介绍)
sizeN50Number宽=高=size 值, 如设置 width 和 height 属性, 会覆盖 size 属性
widthN-Number图片宽度
heightN-Number图片高度
colorN根据背景色自动计算String字体颜色
backgroundColorN随机颜色String背景颜色
isShowBgColorNfalseString当存在 src 时, 是否显示 backgroundColor 背景色
radiusN有图时默认为: 0, 无图时默认是: 50Number图片圆角
customStyleN{}Object自定义样式

mode 值

说明
aspectFill保持纵横比缩放图片,只保证图片的短边能完全显示出来。也就是说,图片通常只在水平或垂直方向是完整的,另一个方向将会发生截取
scaleToFill不保持纵横比缩放图片,使图片的宽高完全拉伸至填满 image 元素
aspectFit保持纵横比缩放图片,使图片的长边能完全显示出来。也就是说,可以完整地将图片显示出来
widthFix宽度不变,高度自动变化,保持原图宽高比不变
heightFix高度不变,宽度自动变化,保持原图宽高比不变

支持插槽

<!-- 实例 -->
<image-pro>插槽</image-pro>

事件

事件名说明
success图片加载成功
error图片加载失败
1.4.5

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.6

5 years ago

1.3.5

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago