uniapp obtiene el estado de la red de telefonía móvil y la información del sistema de telefonía móvil (como 4g, wifi)

Primero mire el código, simplemente cópielo y úselo. (El método integrado de Uni uni.getNetworkType se usa para obtener el estado de la red, uni.getSystemInfo se usa para obtener el sistema de telefonía móvil)

<template>
	<view>
		<view @click="getNetworkType">点击获取状态</view>
		<view>
			网络状态为:{
    
    {
    
    TypeOfNow}}
		</view>
	</view>
</template>

<script>
	export default {
    
    
		data() {
    
    
			return {
    
    
				TypeOfNow:'未获取'
			};
		},
		methods:{
    
    
			getNetworkType() {
    
     //获取网络状态
				const _this = this ; //改变this指向
				uni.getNetworkType({
    
    
					success: (res) => {
    
    
						console.log(res)
						// res的取值为 {errMsg: "getNetworkType:ok",networkType: "wifi"}
						_this.TypeOfNow = res.subtype || res.networkType
					},
			        fail: () => {
    
    
			            uni.showModal({
    
    
			            	content:'获取失败!',
			                showCancel:false
			            })
			        }
				})
				
				uni.getSystemInfo({
    
     //获取手机系统信息
					success: (res) => {
    
    
						console.log('当前手机系统信息为',res)
					}
				})
				
			},
		}
	}
</script>

<style lang="scss">

</style>

Si tienes alguna pregunta sobre uniapp o no entiendes este método, puedes dejar un mensaje, te responderé lo antes posible y te ayudaré a resolverlo.

Supongo que te gusta

Origin blog.csdn.net/weixin_47821281/article/details/111219724
Recomendado
Clasificación