- 小程序调用API获取网络状态,但无法显示网络状态?
跟着教程学习获取网络状态,在电脑端小程序开发工具运行教程给的代码发现:无法获取网络状态。不知道问题出在哪?控制台也没有给出报错信息。 [图片] [图片] 教程中的index.js文件内容如下: Page({ data: { status: '获取中……' }, onLoad: function(options) { var that = this wx.getNetworkType({ //调用获取网络类型函数 success: function(res) { that.setData({ status: res.networkType }) }, }) wx.onNetworkStatusChange(function(res) { //调用监听网络状态变化的函数 if (res.isConnected) { that.setData({ status: res.networkType //如果联网状态,显示网络类型 }) } else { that.setData({ status: '未联网!' }) } }) }, wifiStatus: function() { var that = this wx.getConnectedWifi({ //获取已经连接的Wifi success: function(res) { that.setData({ res: res.wifi }) } }) } }) 教程中的index.wxml 文件内容如下: <view class='box'> <view class='title'>网络状态</view> <view>当前网络状态是:{{status}}</view> <button type='primary' bindtap='wifiStatus'>Wi-Fi状态</button> <view> <view>SSID: {{res.SSID}}</view> <view>BSSID: {{res.BSSID}}</view> <view>安全性: {{res.secure}}</view> <view>信号强度: {{res.signalStrength}}</view> </view> </view>
2021-06-19 - 单行多个button按钮之间为什么无空隙?
最近在学习小程序开发,自己手敲的代码,和教程代码一样(通过工具逐行比对了代码,确保没有敲错代码),是运行效果不一样,不知道问题出在哪里了?恳请大神赐教 [图片] [图片] 我敲的代码: <!--index.wxml--> <view class="box"> <view class='title'>基本绘图</view> <view> <canvas canvas-id="myCanvas" ></canvas> </view> <view class='btnLayout'> <button type='primary' bindtap="clear">清除</button> <button type='primary' bindtap="drawDot">画点</button> <button type='primary' bindtap="drawCircle">画圆</button> </view> <view class='btnLayout'> <button type='primary' bindtap="drawDash">画虚线</button> <button type='primary' bindtap="capAndJoin">端点交点</button> <button type='primary' bindtap="drawText">画字</button> </view> <view class='btnLayout'> <button type='primary' bindtap="circularGrad">圆形渐变</button> <button type='primary' bindtap="shadowRect">阴影矩形</button> <button type='primary' bindtap="translucent">半透明</button> </view> </view> /**index.wxss**/ canvas { width: 100%; height: 340px; background-color: cornflowerblue; } button { width: 100px; } .btnLayout { display: flex; flex-direction: row; margin: 10px; justify-content: space-around; } 教材附带的代码: <!--pages/API/Drawing/index.wxml--> <view class="box"> <view class='title'>基本绘图</view> <view> <canvas canvas-id="myCanvas" ></canvas> </view> <view class='btnLayout'> <button type='primary' bindtap="clear">清除</button> <button type='primary' bindtap="drawDot">画点</button> <button type='primary' bindtap="drawCircle">画圆</button> </view> <view class='btnLayout'> <button type='primary' bindtap="drawDash">画虚线</button> <button type='primary' bindtap="capAndJoin">端点交点</button> <button type='primary' bindtap="drawText">画字</button> </view> <view class='btnLayout'> <button type='primary' bindtap="circularGrad">圆形渐变</button> <button type='primary' bindtap="shadowRect">阴影矩形</button> <button type='primary' bindtap="translucent">半透明</button> </view> </view> /* pages/API/Drawing/index.wxss */ canvas { width: 100%; height: 340px; background-color: cornflowerblue; } button { width: 100px; } .btnLayout { display: flex; flex-direction: row; margin: 10px; justify-content: space-around; /* 弹性项目沿主轴方向平均分布,两边留有一半的间隔空间。 */ }
2021-06-08