提交 452d3204 编写于 作者: taohebin@dcloud.io's avatar taohebin@dcloud.io

getnetworktype 例子

上级 dc06dd5c
......@@ -545,6 +545,15 @@
}
}
,{
"path" : "pages/API/get-network-type/get-network-type",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
}
],
"globalStyle": {
"pageOrientation": "portrait",
......
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view style="background:#FFFFFF; padding:40rpx;">
<view class="uni-hello-text uni-center">网络状态</view>
<view v-if="hasNetworkType === false">
<view class="uni-h2 uni-center uni-common-mt">未获取</view>
<view class="uni-hello-text uni-center uni-common-mt">请点击下面按钮获取网络状态</view>
</view>
<view v-if="hasNetworkType === true">
<view class="uni-h2 uni-center uni-common-mt">{{networkType}}</view>
</view>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="getNetworkType">获取设备网络状态</button>
<button class="uni-common-mt" @tap="clear">清空</button>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: 'getNetworkType',
hasNetworkType: false,
networkType: '',
connectedWifi: '',
pageVisible: false
}
},
onLoad() {
this.pageVisible = true;
},
onUnload: function() {
this.pageVisible = false;
this.networkType = '';
this.hasNetworkType = false;
},
methods: {
getNetworkType: function() {
uni.getNetworkType({
success: (res) => {
console.log(res)
this.hasNetworkType = true;
this.networkType = res.networkType
},
fail: () => {
if (this.pageVisible) {
uni.showModal({
content: '获取失败!',
showCancel: false
})
}
}
})
},
clear: function() {
this.hasNetworkType = false;
this.networkType = '';
this.connectedWifi = '';
},
}
}
</script>
<style>
</style>
\ No newline at end of file
......@@ -2,9 +2,9 @@
<view style="height: 100%;width: 100%;">
<page-head :title="title"></page-head>
<view class="container">
<list class="uni-list" :refresher-enabled="true" @refresherrefresh="onRefresherrefresh"
<list class="uni-list-inner" :refresher-enabled="true" @refresherrefresh="onRefresherrefresh"
:refresher-triggered="refresherTriggered">
<cell class="list_cell" v-for="(item, index) in dataList" :key="item.id">
<cell v-for="(item, index) in dataList" :key="item.id">
<view class="list-item">
<text class="list-item-title" :value="item.name"></text>
</view>
......@@ -45,7 +45,7 @@
</script>
<style>
.uni-list {
.uni-list-inner {
background-color: #eee;
position: relative;
width: 100%;
......@@ -61,12 +61,6 @@
border: dashed;
height: 100%;
width: 100%;
}
.list_cell{
display: flex;
justify-content: center;
align-items: center;
}
.list-item {
......@@ -74,8 +68,8 @@
margin-right: 12px;
margin-top: 12px;
padding: 20px;
border-radius: 5px;
background-color: #fff;
border-radius: 5px;
}
.list-item-title {
......
......@@ -121,7 +121,8 @@
pages: [
{
name: "获取设备网络状态",
url: "get-network-type",
url: "get-network-type",
enable:true
},
{
name: "获取系统信息",
......
......@@ -71,7 +71,7 @@
// #endif
{
name:'list',
enable:false
enable:true
}
] as Page[]
}, {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册