async submit(){
this.form.imgs=await this.uploads()
this.$api.http.post('/add_record',this.form).then(res=>{
})
},
//小程序不支持多文件上传
async uploads(){
const that=this
let arr=[]
for (let k in that.imgList) {
arr[k]=await that.up_img(that.imgList[k])
}
return arr;
},
up_img(url){
return new Promise((resolve, reject) => {
uni.uploadFile({
url: 'https://xxx.com/up_img', //仅为示例,非真实的接口地址
filePath: url,
name: 'img',
header: {
token:uni.getStorageSync("token")
},
formData: {
'user': 'test'
},
success: (uploadFileRes) => {
resolve(uploadFileRes.data);
}
});
})
},
ChooseImage() {
uni.chooseImage({
count: 20, //默认9
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album'], //从相册选择
success: (res) => {
if (this.imgList.length != 0) {
this.imgList = this.imgList.concat(res.tempFilePaths)
} else {
this.imgList = res.tempFilePaths
}
}
});
},
ViewImage(e) {
uni.previewImage({
urls: this.imgList,
current: e.currentTarget.dataset.url
});
},
DelImg(e) {
uni.showModal({
title: '删除',
content: '确定要删除吗?',
cancelText: '否',
confirmText: '是',
success: res => {
if (res.confirm) {
this.imgList.splice(e.currentTarget.dataset.index, 1)
}
}
})
}
async函数返回一个 Promise 对象,可以使用then方法添加回调函数。当函数执行的时候,一旦遇到await就会先返回,等到异步操作完成,再接着执行函数体内后面的语句。
全局取消原生导航栏
在pages.json的globalStyle里,有个navigationStyle设置,默认是default,即带有原生导航栏。app端打包后默认是沉浸式,去掉这个设置就是原生导航栏。
也可以设置为custom。
在设为custom后,所有页面都没有原生导航。
但在微信小程序里,右上角始终都有一个胶囊按钮。
很多微信小游戏界面上也没原生导航栏,但有胶囊按钮。
一般App里不会使用这个参数配置。建议个别页面单独设置不使用原生导航
uni地图选择出现过地图是沉浸式,头部被挡住,升级hbuilder后打包正常。
单独去除原生导航栏
{
"path" : "pages/log/log",
"style" : {
"navigationStyle":"custom"
}
}
沉浸式高度
height:var(–status-bar-height);
关于hbuilder真机调试总是提示手机未授权,又没有弹出提示弹框的问题
这个问题百度了很多方法,插、拔。手机重启都没有解决,最后是adb应该有问题。
打开cmd窗口,切换至adb所在目录,执行命令adb devices弹出授权窗口授权ok。