uniapp + uview —— 上传图片

index.vue

<u-upload
   ref="upload"
   max-count="6"
   :header="header"
   :action="action"
   :custom-btn="true"
   :show-tips="false"
   :show-progress="false"
   @on-success="successUpload"
   @on-remove="removeFile"
 ></u-upload>

接口、请求头部

data() {
	fileList: [],
	header: {
      'Content-Type': 'multipart/form-data', //设置multipart/form-data格式
       Authorization: 'Bearer ' + uni.getStorageSync('access_token')
     },
}
computed: {
    action() {
      return url.baseURL + '/upload' // ule.baseURL 从配置地址处引入,获取当前环境url
    }
  },

方法

// 上传
successUpload(data, index, lists, name) {
   this.fileList.push(data.data)
 },
 // 移除
 removeFile(index, lists, name) {
   this.fileList.splice(index, 1)
 }

你可能感兴趣的:(小程序,uni-app,微信小程序)