- 업로드된 이미지를 표시하기 위해 wxml 파일에 버튼과 이미지 태그를 추가합니다.
<view> <button bindtap="chooseImage">选择图片</button> <image src="{ {imageUrl}}" /> </view>
- js 파일에 사진 선택 및 사진 업로드 방법 추가
Page({ data: { imageUrl: '' }, chooseImage() { wx.chooseImage({ count: 1, // 可选择的图片数量 sizeType: ['compressed'], // 压缩图片 sourceType: ['album', 'camera'], // 来源:相册或相机 success: (res)=> { // 将选择的图片上传到服务器 this.uploadImage(res.tempFilePaths[0]); } }) }, uploadImage(imagePath) { wx.uploadFile({ url: '服务器地址', // 上传图片的接口地址 filePath: imagePath, // 图片文件路径 name: 'image', // 文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容 success: (res) => { // 上传成功后,将服务器返回的图片地址更新到image标签中 this.setData({ imageUrl: res.data }); }, fail: function (res) { console.log(res); } }) } })
WeChat 애플릿은 이미지 업로드를 실현합니다(클리어 버전).
추천
출처blog.csdn.net/qq_42044542/article/details/129666130
추천
행