01
默认
<cu-image :src="logo" />
图片用于展示图像内容,支持裁剪模式、圆角与加载失败占位。
整目录放进工程即用:easycom 按标签逐个解析,页面写哪个组件就只编译哪个,不写 import,也没有全局注册这一步;单个组件也可以显式引入(第 4 步,可选);主题层在 App.uvue 引入一次即可。
# 1 整目录放进工程(easycom 自动解析) your-project/ └── uni_modules/ └── colorui-x/ # 2 App.uvue 全局引入主题层(一次) @import 'uni_modules/colorui-x/theme/base.css'; @import 'uni_modules/colorui-x/theme/layout.css'; @import 'uni_modules/colorui-x/theme/color.scss'; // 颜色工具类(.bg-* / .text-*) # 3 页面里直接用,不写 import(只编译用到的组件) <cu-image /> # 4 单个组件也可以显式引入(可选,不用 easycom 时) import CuImage from '@/uni_modules/colorui-x/components/cu-image/cu-image.uvue'
组件样式自包含(只依赖包内 token.scss),主题层是给页面工具类用的,不参与组件注册。两种安装方式见 快速上手。
| Android | iOS | HarmonyOS | Web(H5) | 微信小程序 | 支付宝小程序 |
|---|---|---|---|---|---|
| √ | — | — | √ | — | — |
Android 列取自本仓真机逐屏判定(√ 已验 / — 待复核 / × 已登记缺陷,本件当前为「真机已验」)。
Web 列只表示已编出可运行的预览产物,非真机渲染。
其余三端没有任何实测证据,不作支持承诺。
<cu-image :src="logo" />
<cu-image :src="logo" shape="circle" /> <cu-image :src="logo" :radius="10" /> <cu-image :src="logo" shape="circle" :radius="10" :width="160" :height="160" />
<cu-image :src="logo" mode="aspectFit" :width="160" :height="120" /> <cu-image :src="logo" mode="widthFix" :width="160" /> <cu-image :src="logo" mode="scaleToFill" :width="160" :height="120" /> <cu-image :src="logo" mode="not-a-mode" :width="160" :height="120" />
<cu-image src="" :width="160" :height="120" /> <cu-image src="" :showError="false" :width="160" :height="120" /> <cu-image src="/static/logo-missing.png" :width="160" :height="120" />
<cu-image src="" :width="200" :height="120" errorIcon="cuIcon-roundclosefill" /> <cu-image src="" :width="200" :height="120"> <template #error> <text> 自定义错误占位文字 </text> </template> </cu-image>
<cu-image :src="logo" :width="160" :height="120" :lazyLoad="false" :showMenuByLongpress="true" :showLoading="true" loadingIcon="cuIcon-loading" :fade="false" :duration="300" :webp="true" bgColor="#39b54a" @click="onEcho" />
<cu-image :src="logo" :width="120" :height="120" customClass="custom-class" /> <cu-image :src="logo" :customStyle="blockStyle" :width="120" :height="120" /> <cu-image :src="logo" :width="0" :height="0" />
这一节的交互由演示页脚本驱动,效果见右侧实时预览。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| 图片来源 | |||
| src | 图片地址;为空直接进入错误态 | String | '' |
| mode | 裁剪模式,透传给 <image mode> | String | 'aspectFill' |
| 尺寸与形状 | |||
| width | 宽度,px 契约值;运行时 ×2 换算成 rpx,不收百分比 | Number | 300 |
| height | 高度,px 契约值;同上 | Number | 225 |
| shape | square / circle | String | 'square' |
| radius | 圆角,px 契约值;大于 0 时裁切 | Number | 0 |
| 错误态 | |||
| showError | 失败时是否显示错误遮罩 | Boolean | true |
| errorIcon | 失败遮罩里的图标名 | String | 'cuIcon-roundclose' |
| 交互与样式 | |||
| customStyle | 根节点内联样式 | Object | (): UTSJSONObject => ({}) |
| customClass | 追加到根节点的类名 | String | '' |
| 声明保留但不被消费 | |||
| lazyLoad | 懒加载开关;本仓 image 未接该属性,传了不生效 | Boolean | true |
| showMenuByLongpress | 微信长按菜单;本仓不接通 | Boolean | true |
| loadingIcon | 加载中的图标名;本仓不渲染加载遮罩 | String | 'cuIcon-pic' |
| showLoading | 是否显示加载遮罩;本仓不实现加载遮罩 | Boolean | true |
| fade | 淡入开关;本仓过渡层未实现,传了不生效 | Boolean | true |
| webp | 微信 webp 开关;本仓不接通 | Boolean | false |
| duration | 淡入时长;随 fade 一并未实现 | Number | 500 |
| bgColor | 加载遮罩底色;本仓无加载遮罩,传了不生效 | String | '#f3f4f6' |
| url | 不产生跳转,请在 @click 里自行跳转 | String | '' |
| linkType | 不产生跳转,同上 | String | 'navigateTo' |
| 事件 | 说明 | 类型 | 默认值 | 平台差异说明 |
|---|---|---|---|---|
| @click | 点击图片时触发,无载荷 | Handler | - | 各端一致 |
| @load | 加载成功时触发,回传 { width, height } | Handler | - | 各端一致 |
| @error | 加载失败时触发,回传 { errMsg } | Handler | - | 各端一致 |
| slot | 说明 |
|---|---|
| error | 加载失败时的自定义内容;不填时显示 errorIcon |
宽高只收数字 :width / height 是 px 契约值,传百分比不生效。