外观
NoNetwork 无网络提示
约 681 字大约 2 分钟
2025-10-31
该组件无需任何配置,引入即可,内部自动处理所有功能和事件,有如下特点:
- 如果没有网络,该组件会以
fixed定位,并且以很大的z-index值覆盖原来的内容。一旦有网络了,会自动隐藏该组件,实现自动化 - 在APP上,嵌入了5+接口,可以直接打开手机的设置页面,方便用户进行网络相关的设置
说明
- 应用有网络时,是不会触发本组件的,为了测试此功能,请关闭手机的数据连接以及WiFi即可
- 由于普通的组件无法覆盖原生组件,所以本组件不适用那些有
video,map等原生表现的组件的页面,可以自行使用uni的cover-view组件修改
基本使用
<template>
<view>
<un-no-network
@disconnected="disconnected"
@connected="connected"
@retry="retry"
></u-no-network>
<view class="u-content">
<view class="u-content__circle">
<un-icon
name="checkbox-mark"
color="#fff"
size="30"
></un-icon>
</view>
<text class="u-content__normal">网络正常</text>
</view>
</view>
</template>
<script setup lang="ts">
const disconnected = () => {
console.log('disconnected');
}
const connected = () => {
console.log('connected');
}
const retry = () => {
console.log('retry');
}
</script>
<style lang="scss" scoped>
.u-content {
padding: 150px 60px 0;
@include flex(column);
align-items: center;
justify-content: center;
&__circle {
background-color: $u-success;
@include flex;
border-radius: 100px;
width: 60px;
height: 60px;
align-items: center;
justify-content: center;
}
&__normal {
font-size: 15px;
color: $u-success;
margin-top: 15px;
}
}
</style>Props
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| tips | 没有网络时的提示语 | string | 哎呀,网络信号丢失 |
| zIndex | 组件的z-index值 | string | number | - |
| image | 无网络的图片提示,可用的src地址或base64图片 | string | - |
| customStyle | 自定义样式 | object | {} |
Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
| retry | 用户点击页面的"重试"按钮时触发 | - |
| connected | "重试"后,有网络触发 | - |
| disconnected | "重试"后,无网络触发 | - |
Scss 变量
| 变量名 | 默认值 | 说明 |
|---|---|---|
| $un-no-network-margin-top | -100px | 无网络提示组件整体上边距 |
| $un-no-network-tips-color | $text-color-muted | 提示文字颜色 |
| $un-no-network-tips-font-size | $text-sm | 提示文字大小 |
| $un-no-network-tips-margin-top | 15px | 提示文字上边距 |
| $un-no-network-app-margin-top | 6px | APP平台提示文字上边距 |
| $un-no-network-app-setting-color | $text-color-muted | APP平台设置提示文字颜色 |
| $un-no-network-app-setting-font-size | $text-sm | APP平台设置提示文字大小 |
| $un-no-network-app-to-setting-font-size | $text-sm | APP平台"设置"文字大小 |
| $un-no-network-app-to-setting-color | $color-primary | APP平台"设置"文字颜色 |
| $un-no-network-app-to-setting-margin-left | 3px | APP平台"设置"文字左边距 |
| $un-no-network-retry-margin-top | 15px | 重试按钮上边距 |
提示
组件内部默认使用 scss 变量,如需修改,请查看 scss 变量使用 文档
