uni.showToast({ icon:'none', title: '地址不正确:'+err.errMsg, })中设置icon为error为什么不显示错误
时间: 2024-03-19 21:45:48 浏览: 22
在uni.showToast方法中,icon参数可以设置为none、success、loading三种值。如果设置为error,是无法显示错误图标的,因为error不是icon参数支持的取值,只有none、success和loading才是合法的取值。
如果你想显示错误图标,可以将icon参数设置为success,同时在title中显示错误信息。如下所示:
```
uni.showToast({
icon: 'success',
title: '错误信息:' + err.errMsg
})
```
这样就能够在提示框中同时显示错误图标和错误信息了。
相关问题
wx.showToast({ title: '该用户不存在', icon: 'error', duration: 2000 })
这段代码是小程序(微信小程序)中调用 showToast 方法,用于显示一个带有图标和文本的消息提示框,内容为“该用户不存在”,显示时间为 2 秒。
具体解释如下:
- `wx.showToast` 表示调用小程序 API 中的 showToast 方法。
- `title: '该用户不存在'` 表示要显示的消息框文本内容为“该用户不存在”。
- `icon: 'error'` 表示消息框左侧的图标为错误图标。
- `duration: 2000` 表示消息框的显示时间为 2 秒。
因此,这段代码的作用是在小程序中显示一个带有“该用户不存在”的错误提示框,提示信息展示 2 秒,并在左侧显示一个错误图标。
请根据错误信息修改一下代码 const uploadVideo = () => { // 提醒用户下载中 uni.showToast({ title: "下载中", icon: "loading" }) // 1 将远程文件下载到小程序的内存中 uni.downloadFile({ url:state.videourl, success: (res) => { debugger if (res.statusCode === 200) { //保存图片到系统相册 uni.saveVideoToPhotosAlbum({ filePath: res.tempFilePath, success: function() { uni.showToast({ title: "保存成功", icon: "none" }); return }, fail: function() { uni.showToast({ title: "保存失败,请稍后重试", icon: "none" }); return } }); } } }) }
这个错误是由于下载视频时服务器返回了不安全的响应头字段 "content-disposition" 导致的,需要在请求头中添加 `responseType: 'arraybuffer'`,以便正确解析服务器的响应头,代码修改如下:
```javascript
const uploadVideo = () => {
// 提醒用户下载中
uni.showToast({
title: "下载中",
icon: "loading"
})
// 1 将远程文件下载到小程序的内存中
uni.downloadFile({
url: state.videourl,
responseType: 'arraybuffer', // 添加此项
success: (res) => {
debugger
if (res.statusCode === 200) {
//保存图片到系统相册
uni.saveVideoToPhotosAlbum({
filePath: res.tempFilePath,
success: function() {
uni.showToast({
title: "保存成功",
icon: "none"
});
return
},
fail: function() {
uni.showToast({
title: "保存失败,请稍后重试",
icon: "none"
});
return
}
});
}
}
})
}
```
这样应该就可以正常下载视频并保存到系统相册了。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)