提交 136f6fd7 编写于 作者: DCloud-yinjiacheng's avatar DCloud-yinjiacheng

新增image示例

上级 8a78ba06
...@@ -84,7 +84,25 @@ ...@@ -84,7 +84,25 @@
"style": { "style": {
"navigationBarTitleText": "image" "navigationBarTitleText": "image"
} }
}, },
{
"path": "pages/component/image/image-format",
"style": {
"navigationBarTitleText": "image-format"
}
},
{
"path": "pages/component/image/image-mode",
"style": {
"navigationBarTitleText": "image-mode"
}
},
{
"path": "pages/component/image/image-path",
"style": {
"navigationBarTitleText": "image-path"
}
},
{ {
"path": "pages/component/web-view/web-view", "path": "pages/component/web-view/web-view",
"style": { "style": {
......
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-title">
<text class="uni-title-text">支持的图片格式示例</text>
</view>
<view v-for="(item,index) in data" :key="index">
<text class="uni-subtitle-text">{{item.format}}</text>
<view class="uni-center" style="background:#FFFFFF;">
<image class="image" mode="widthFix" :src="item.src"></image>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: 'image-format',
data: [{
format: 'png',
src: '/static/logo.png'
},
{
format: 'jpg',
src: '/static/logo.jpg'
},
{
format: 'webp',
src: '/static/logo.webp'
},
{
format: 'bmp',
src: '/static/logo.bmp'
},
{
format: 'gif',
src: '/static/logo.gif'
}
] as Array < ImageFormat >
}
}
}
class ImageFormat {
format: string;
src: string;
constructor(format: string, src: string) {
this.format = format;
this.src = src;
}
}
</script>
<style>
.image {
margin: 40rpx auto;
width: 200rpx;
}
</style>
\ No newline at end of file
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-title">
<text class="uni-title-text">支持的图片缩放模式示例</text>
</view>
<view v-for="(item,index) in data" :key="index">
<text class="uni-subtitle-text">{{item.mode}}: {{item.description}}</text>
<view class="uni-center" style="background:#FFFFFF;">
<image class="image" :mode="item.mode" src="/static/shuijiao.jpg"></image>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: 'image-mode',
data: [{
mode: 'scaleToFill',
description: '不保持纵横比缩放图片,使图片的宽高完全拉伸至填满 image 元素'
},
{
mode: 'aspectFit',
description: '保持纵横比缩放图片,使图片的长边能完全显示出来。也就是说,可以完整地将图片显示出来'
},
{
mode: 'aspectFill',
description: '保持纵横比缩放图片,只保证图片的短边能完全显示出来。也就是说,图片通常只在水平或垂直方向是完整的,另一个方向将会发生截取'
},
{
mode: 'top',
description: '不缩放图片,只显示图片的顶部区域'
},
{
mode: 'bottom',
description: '不缩放图片,只显示图片的底部区域'
},
{
mode: 'center',
description: '不缩放图片,只显示图片的中间区域'
},
{
mode: 'left',
description: '不缩放图片,只显示图片的左边区域'
},
{
mode: 'right',
description: '不缩放图片,只显示图片的右边区域'
},
{
mode: 'top left',
description: '不缩放图片,只显示图片的左上边区域'
},
{
mode: 'top right',
description: '不缩放图片,只显示图片的右上边区域'
},
{
mode: 'bottom left',
description: '不缩放图片,只显示图片的左下边区域'
},
{
mode: 'bottom right',
description: '不缩放图片,只显示图片的右下边区域'
},
{
mode: 'widthFix',
description: '宽度不变,高度自动变化,保持原图宽高比不变'
},
{
mode: 'heightFix',
description: '高度不变,宽度自动变化,保持原图宽高比不变'
}
] as Array < ImageMode >
}
}
}
class ImageMode {
mode: string;
description: string;
constructor(mode: string, description: string) {
this.mode = mode;
this.description = description;
}
}
</script>
<style>
.image {
margin: 40rpx auto;
width: 200rpx;
height: 200rpx;
background-color: #eeeeee;
}
</style>
\ No newline at end of file
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-title">
<text class="uni-title-text">支持的图片路径示例</text>
</view>
<view v-for="(item,index) in data" :key="index">
<text class="uni-subtitle-text">{{item.description}}</text>
<view class="uni-center" style="background:#FFFFFF;">
<image class="image" mode="widthFix" :src="item.src"></image>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: 'image-path',
data: [{
src: 'https://web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png',
description: '网络路径'
},
{
src: '/static/logo.png',
description: '本地相对路径'
},
{
src: 'file:///storage/emulated/0/Android/data/io.dcloud.uniappx/apps/__UNI__4517034/www/static/logo.png',
description: '本地绝对路径'
},
{
src: 'data:image/*;base64,iVBORw0KGgoAAAANSUhEUgAAAMAAAADACAYAAABS3GwHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAABZ0RVh0Q3JlYXRpb24gVGltZQAwNS8xMi8yM3CzGsQAAAAcdEVYdFNvZnR3YXJlAEFkb2JlIEZpcmV3b3JrcyBDUzbovLKMAAAQGUlEQVR4nO3df5ScVX3H8ffMLpsfBDCkQrQQQiAhHq5EIog+IAKCpwqHcFQKTbQg2AultLUiUDg5gNZfh2CFWjl45UBpg5IaUYugRUsSoDdIUBO9QhAhIYQ0AUlIQn4nO/3jPgPDZmd3Zp4f95mZ7+ucPezOPj8+WZ7v3DvPj3tLlUoFkR5lojJwCDAROAw4PP4aDxwMjAP2B0YBfUAJ2AnsADYD64F18dfzwIqa/6522m7L71/T+UpSAK1RJtoPmAAcARwJTIp/Phj4E2A/YDSwD9ALlJvcRQXYDewCtgFbgFeAl4BVwErgD/HXSqft+kT/oC4lBdAAZaIe4CjgOOA9wLH4g/6gkLlqbACeA34L/BJYAjin7ZagqdqAFEAdykRHAe8HTsMf+JPDJmraGnwxPAwsBJY5bXcFTVRAUgAxZaIRQAR8BDgdmIbvn3eKZ4EFwAPAQqfthsB5CqGrC0CZqBf/Ln8u8Gf4D6vd4I/4YpgP/LfTdmPgPMF0ZQEoEyngfODj+L59N1sL/Bi422m7MGiSALqmAJSJRgFnAxcBZ9BZ3Zu0LAX+DbjHabsucJZcdHwBKBP9KfAp/IHfLV2cpNYD3wWM0/Y3ocNkqWMLQJloCnAZcCFwQNg0basfuBe4xWn7aOgwWei4AogP/M/iD/wRYdN0lPuBOU7bRaGDpKljCkCZaAJwFfBp5MDP0o+ALzltl4QOkoa2L4D4loQrgM8gXZ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pKmjiuAKmWiafhhGmciV5OTeAC4xWn7YOggWejYAqhSJjoCP4vNBciH5UZtwffxb3PaFmI20Kx0fAFUKRPtD5wLfAq527Se5fiHVOY6bZ8PHSYPXVMAteLrCLOAc4BDA8cJbQPwE/yB/6DTdk/gPLnqygKoUibaFzgN3zKcDrwtbKLcvAYsAuYDD4R4GL0ouroAaikT7Qd8ADgLOBWYEjZR6tYADwP3Aw/FI3h3PSmAQSgT9QDH4B/OOQWYDhwSMFIr1uPH2nkUfwpzidN2S9hIxSMF0ABlotHA0fib8Y4HpgGTgKLMzr0Vfz+OA57ATyX0G6ftK0FTtQEpgBbFt2BMBCbHX4fjP1AfBBwIjMHfmtEbf7WiH9iFn2jkNfytxi8Dq4GVwDPA74EVTtv/a3EfXU0KIGXx6dZDgSOBCfjPEhPw1yDGA+OAUXVW34k/K7MO32dfjT/AV+EP9hfyHjqw0/0/VOBpKm24LQkAAAAASUVORK5CYII=',
description: 'Base64'
}
] as Array < ImagePath >
}
}
}
class ImagePath {
src: string;
description: string;
constructor(src: string, description: string) {
this.src = src;
this.description = description;
}
}
</script>
<style>
.image {
margin: 40rpx auto;
width: 200rpx;
}
</style>
\ No newline at end of file
<template> <template>
<view> <view>
<page-head :title="title"></page-head> <page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt"> <view class="uni-padding-wrap uni-common-mt">
<view class="uni-title"> <view class="uni-center" style="background:#FFFFFF;">
<text class="uni-title-text"> <image class="image" :fade-show="true" mode="widthFix" src="/static/logo.png" @error="error"
示例1 @load="load"></image>
</text> </view>
<text class="uni-subtitle-text"> <view class="uni-btn-v">
本地图片 <button type="primary" @tap="imageFormat">图片格式示例</button>
</text> </view>
</view> <view class="uni-btn-v">
<view class="uni-center" style="background:#FFFFFF; font-size:0;"> <button type="primary" @tap="imageMode">图片缩放模式示例</button>
<image class="image" mode="widthFix" src="/static/uni.png" /> </view>
</view> <view class="uni-btn-v">
<view class="uni-title"> <button type="primary" @tap="imagePath">图片路径示例</button>
<text class="uni-title-text"> </view>
示例2 </view>
</text> </view>
<text class="uni-subtitle-text">
网络图片
</text>
</view>
<view class="uni-center" style="background:#FFFFFF; font-size:0;">
<image class="image" mode="widthFix" src="https://web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png" />
</view>
</view>
</view>
</template> </template>
<script> <script>
export default { export default {
data() { data() {
return { return {
title: 'image' title: 'image'
} }
} },
} methods: {
error(event: ImageErrorEvent) {
console.log(event.type, event.detail);
},
load(event: ImageLoadEvent) {
console.log(event.type, event.detail);
},
imageFormat() {
uni.navigateTo({
url: '/pages/component/image/image-format'
});
},
imageMode() {
uni.navigateTo({
url: '/pages/component/image/image-mode'
});
},
imagePath() {
uni.navigateTo({
url: '/pages/component/image/image-path'
});
}
}
}
</script> </script>
<style> <style>
.image { .image {
margin: 40rpx auto; margin: 40rpx auto;
width: 200rpx; width: 200rpx;
} }
</style> </style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册