一 点睛
1 官网: http://uniapp.dcloud.io/api/media/image
2 核心API
- uni.chooseImage(OBJECT)
- uni.previewImage(OBJECT)
二 代码
1 新建 photo.vue
<template>
<view>
<button type="primary" @click="updatePhoto">上传图片</button>
<image v-for="item in imgArr" :src="item" @click="previewImg(item)"></image>
</view>
</template>
<script>
export default {
data() {
return {
imgArr: []
}
},
methods: {
updatePhoto() {
uni.chooseImage({
count: 5, //默认9
success: res => {
this.imgArr = res.tempFilePaths
}
});
},
previewImg(current) {
uni.previewImage({
current: current,
urls: this.imgArr,
loop:true,
indicator:'number'