Look at the code first, just copy and use it. (Uni built-in method uni.getNetworkType is used to obtain network status, uni.getSystemInfo is used to obtain mobile phone system)
<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>
If you have any questions about uniapp or you don’t understand this method, you can leave a message, I will reply as soon as possible and help you solve it.