11、图片上传和下载

1、图片上传

uni.chooseImage(OBJECT)

调用uni.chooseImage(OBJECT)即可打开弹窗选图片

从本地相册选择图片或使用相机拍照。App端如需要更丰富的相机拍照API(如直接调用前置摄像头),参考plus.camera

OBJECT 参数说明

image

success 返回参数说明

image

2、浏览图片

uni.previewImage(OBJECT)

预览图片。

OBJECT 参数说明

image

current 参数说明

current 为当前显示图片的链接/索引值,不填或填写的值无效则为 urls 的第一张。App平台在 1.9.5至1.9.8之间,current为必填。不填会报错。

注意,当 urls 中有重复的图片链接时:

传链接,预览结果始终显示该链接在 urls 中第一次出现的位置。

传索引值,在微信/百度/字节跳动小程序平台,会过滤掉传入的 urls 中该索引值之前与其对应图片链接重复的值。其它平台会保留原始的 urls 不会做去重处理。

更多参考官网:API->媒体->图片

<template>
	<view>
		<button v-on:click="chooseImage">上传图片</button>
		<image v-for='(item) in imageFile' :src='item' @click='clickImage(item)'></image>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				imageFile:[]
			}
		},
		methods:{
			chooseImage(){
				uni.chooseImage({
					count:5,
					success:res=>{
						this.imageFile=res.tempFilePaths;
					}
				})
			},
			
			clickImage(current){
				uni.previewImage({
					current,
					urls:this.imageFile
				});
			}
		}
	}
</script>
posted @ 2022-06-22 21:40  青仙  阅读(136)  评论(0编辑  收藏  举报