Skip to content

NoNetwork 无网络提示

该组件无需任何配置,引入即可,内部自动处理所有功能和事件,有如下特点:

  • 如果没有网络,该组件会以fixed定位,并且以很大的z-index值覆盖原来的内容。一旦有网络了,会自动隐藏该组件,实现自动化
  • 在APP上,嵌入了5+接口,可以直接打开手机的设置页面,方便用户进行网络相关的设置

说明

  1. 应用有网络时,是不会触发本组件的,为了测试此功能,请关闭手机的数据连接以及WiFi即可
  2. 由于普通的组件无法覆盖原生组件,所以本组件不适用那些有videomap等原生表现的组件的页面,可以自行使用uni的cover-view组件修改

平台差异说明

App(vue)App(nvue)H5小程序

基本使用

html
<template>
	<view>
		<up-no-network
			@disconnected="disconnected"
			@connected="connected"
			@retry="retry"
		></up-no-network>
		<view class="up-content">
			<view class="up-content__circle">
				<up-icon
					name="checkbox-mark"
					color="#fff"
					size="30"
				></up-icon>
			</view>
			<text class="up-content__normal">网络正常</text>
		</view>
	</view>
</template>
js
<script setup>  
// 定义方法  
function disconnected() {  
    console.log('disconnected');  
}  
  
function connected() {  
    console.log('connected');  
}  
  
function retry() {  
    console.log('retry');  
}  
</script>
js
<script>
	export default {
		methods: {
			disconnected() {
				console.log('disconnected');
			},
			connected() {
				console.log('connected');
			},
			retry() {
				console.log('retry');
			}
		},
	}
</script>
css
<style lang="scss" scoped>
	.up-content {
		padding: 150px 60px 0;
		@include flex(column);
		align-items: center;
		justify-content: center;

		&__circle {
			background-color: $up-success;
			@include flex;
			border-radius: 100px;
			width: 60px;
			height: 60px;
			align-items: center;
			justify-content: center;
		}

		&__normal {
			font-size: 15px;
			color: $up-success;
			margin-top: 15px;
		}
	}
</style>

右侧演示页面源代码地址

点击以下链接以查看右侧演示页面的源码


 github  gitee

API

Props

参数说明类型默认值可选值
tips没有网络时的提示语String哎呀,网络信号丢失-
zIndex组件的z-indexString | Number10080-
image无网络的图片提示,可用的src地址或base64图片String--

Events

事件名说明回调参数
retry用户点击页面的"重试"按钮时触发-
connected"重试"后,有网络触发-
disconnected"重试"后,无网络触发-