上传图片
uni.chooseImage方法从本地相册选择图片或使用相机拍照。
代码示例:
<template>
<view>
<button @click="chooseImg" type="primary">上传图片</button>
<view>
<image v-for="item in imgArr" :src="item" :key="index"></image>
</view>
</view>
</template>
<script>
export default {
data () {
return {
imgArr: []
}
},
methods: {
chooseImg () {
uni.chooseImage({
count: 9,
success: res=>{
this.imgArr = res.tempFilePaths
}
})
}
}
}
</script>
预览图片
结构
<view>
<image v-for="item in imgArr" :src="item" @click="previewImg(item)" :key="item">
</image>
</view>
预览图片的方法
previewImg (current) {
uni.previewImage({
urls: this.imgArr,
current
})
}
本篇文章讲解uni-app中的图片上传与预览,若有什么地方不明确或某些位置不太懂得请在评论中指出,后期我会继续出更多的基础教学谢谢各位支持 ,谢谢大家