/*htnl*/
<view class="img_lists">
<image @click="chooseFile" src="../../static/uploadImg.png"></image> //点击这张图片会调起函数
//循环coverImg就可以显示小图,点击即可实现预览效果
<image v-for="(item,i) in coverImg" :src="item" :key="i" @click="previewImg(item)"></image>
</view>
export default {
data() {
return {
coverImg: [],
}
},
method: {
chooseFile() {
await uni.chooseImage({
count: 1,
success: res => {
this.coverImg = res.tempFilePaths
}
});
}
},
previewImg(current,) {
uni.previewImage({
current,
urls this.coverImgSrc,
loop: true,
indicator: "default"
})
},
async urlTobase64(url) {
let res = await new Promise((resolve) => {
uni.request({
url: url,
method: 'GET',
responseType: 'arraybuffer',
success: res => {
resolve(res)
}
})
})
let base64 = wx.arrayBufferToBase64(res.data);
base64 = `data:image/jpeg;base64,${base64}`
console.log(base64)
},
function upAudioFile(){
let res= await new Promise((resolve) => {
uni.chooseFile({
count: 1,
extension: ['.mp3'],
success: res => {
resolve(res)
}
});
})
console.log(res)
this.baseAudioFile = await this.urlTobase64(res.tempFilePaths[0])
},
}