Taro.onNetworkStatusChange(callback)
Listens on the network status change event.
Type
(callback: Callback) => void
Parameters
Callback
The callback function for the network status change event.
(result: CallbackResult) => void
| Property | Type |
|---|---|
| result | CallbackResult |
CallbackResult
| Property | Type | Description |
|---|---|---|
| isConnected | boolean | Indicates whether it is connected to the network |
| networkType | "wifi" | "2g" | "3g" | "4g" | "unknown" | "none" | Network type |
Sample Code
Taro.onNetworkStatusChange(function (res) {
console.log(res.isConnected)
console.log(res.networkType)
})
API Support
| API | WeChat Mini-Program | H5 | React Native |
|---|---|---|---|
| Taro.onNetworkStatusChange | ✔️ | ✔️ | ✔️ |