uniapp --本地图片的上传

uniapp 为我们提供了专门上传图片的方法 chooseImage({})

更多点击查看详情

我们想要实现点击按钮上传图片并显示到页面上这样一个业务:

<button @click="postImg">点击上传图片</button>
<image v-for="item in list" :src="item" alt="图片"></image>
			postImg(){
    
    
				// 本地上传图片
				uni.chooseImage({
    
    
				// 限制上传图片张数
					count:6,
					// 成功之后的回调函数
					success:res=> {
    
    
						this.list = [...res.tempFilePaths]
					}
				})
			}

图片上传

点击图片预览:

<image v-for="item in list" :src="item" alt="图片" @click="previewImage(item)"></image>
			previewImage(current){
    
    
				// 图片预览
				uni.previewImage({
    
    
					current,
					urls:this.list
				})
			}

猜你喜欢

转载自blog.csdn.net/weixin_63836026/article/details/126649052