图片上传功能,代码如下:
<template>
<view class="picker_card" v-model="identityCardPicN" @tap="selectImg()">
<image class="card_img" :src="identityCardPicN ? identityCardPicN : idIcon" mode="">
</image>
</view>
</template>
<script>
export default {
name: 'promise',
components: {
},
data() {
return {
idIcon: '本地图片路径',//如果没有上传图片,默认加载本地图片
identityCardPicN: '',
}
},
methods: {
// 选择图片的功能
chooseImg() {
var that = this
var uploadUrl = '接口路径'
var token = uni.getStorageSync(ACCESS_TOKEN)
//调用uniapp选择接口的API
uni.chooseImage({
count: 1, //默认9 自定义为1只可选择一张图片
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认