参考文档:
/**
* 获取网络状态
* @return networkAvailable
* @return networkType
*/
export const getNetworkType = async () => {
const { networkAvailable, networkType } = await my.getNetworkType()
return {
networkAvailable,
networkType,
}
}
async onPullDownRefresh() {
//使用封装的方法
const { networkAvailable } = await getNetworkType()
//或者直接使用api
//const { networkAvailable, networkType } = await my.getNetworkType()
if (networkAvailable) {
//TODO网络可用
} else {
my.showToast({
content: '当前网络不可用,请检查网络',
})
}
},