在uniapp中,提供了uni.chooseImage和uni.uploadFile接口,我们很容易的就可以实现图片的上传,而uni.previewImage是官方提供的预览功能,下面来展示下:
先看下template部分
<template>
<view>
<view class="uni-addfile" @click="chooseImage">+ 请选择文件</view>
<image :src="tempFilePath[0]" @tap="_previewImage(tempFilePath[0])" mode="widthFix" >
<button class="btn-savefile" @click="saveFile">保存文件</button>
</view>
</template>
下面是script部分
<script>
export default {
data() {
return {
title: 'saveFile',
tempFilePath: '',
savedFilePath: ''
}
},
methods: {
chooseImage() {
uni.chooseImage({
count: 1,
success: (res) => {
this.tempFilePath = res.tempFilePaths[0];