参考文档:
/**
* 获取网络状态
* @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: '当前网络不可用,请检查网络',
})
}
},
标签:支付宝,const,getNetworkType,程序,网络,return,获取,networkType,networkAvailable
From: https://www.cnblogs.com/yangyukeke/p/17417378.html