<template>
<view class="content">
<image :src="image"></image>
<button @click="copy()">上传图片</button>
<button @click="get()">终端上传</button>
</view>
</template>
<script>
import img from '../../static/img/indexChoice.png'
export default {
data() {
return {
image: '',
}
},
onLoad() {
this.uploadTask = null
},
methods: {
copy() {
uni.chooseImage({
success: (res) => {
let tempFilePaths = res.tempFilePaths
this.uploadTask = uni.uploadFile({
url: 'http://vueshop.glbuys.com/api/user/myinfo/formdatahead?token=1ec949a15fb709370f',
filePath: tempFilePaths[0],
name: 'headfile',
success: (uploadFileRes) => {
let data = JSON.parse(uploadFileRes.data)
if (data.code === 200) {
this.image = 'http://vueshop.glbuys.com/userfiles/head/' + data
.data.msbox
}
}
});
}
})
},
get() {
this.uploadTask.abort();
}
}
}
</script>
<style scoped>
</style>
uniapp 上传文件
最新推荐文章于 2024-07-15 10:34:14 发布