上传图片
注意:小程序时必须要写header:{“Content-Type”: “multipart/form-data”}, h5是必须省略
chooseImg(){
let that = this
uni.chooseImage({
count: 1,
success: (res)=> {
const tempFilePaths = res.tempFilePaths[0];
uni.uploadFile({
url:`https://test-mall.lhsc99.cn/index.php`,
filePath: tempFilePaths, // uni.chooseImage函数调用后获取的本地文件路劲
name:'file', //后端通过'file'获取上传的文件对象
formData:{
access_id:uni.getStorageSync("access_id"),//
store_id:1,
store_type:2,
module:'app',
action:'user',
app:'uploadImg',
type:'comments',
file:tempFilePaths
},
// #ifdef MP-WEIXIN
header:{"Content-Type": "multipart/form-data"},
//#endif
success:(res) => {
}
});
}
});
}
uni-app h5 端的ios图片不能加载问题
uni-app h5端 ios只能加载https的图片 (坑坑坑)
uni-app 使用deep 穿透微信小程序生效 h5无作用
需要在methods同级下加一个 :
options: { styleIsolation: ‘shared’ },
uni-app post请求如何传递数组 参数
在开发中我们接口上传图片是post请求 无法传递一个数组 解决方法如下
我们可以把数据转换成字符串 然后拼接到请求地址后后面
拼接字符串格式:image[]=arr[0]&image[]=arr[1]
imgUrlClick(imgArr){
return '?images[]='+imgArr.join('&images[]=')
},