先上代码:
<template>
<view class="home">
<button class="home-but" @click="authorizeLocation">扫码连WIFI</button>
</view>
</template>
<script>
export default {
data() {
return {}
},
onLoad() {
},
methods: {
authorizeLocation() {
uni.authorize({
scope: 'scope.userLocation',
success: () => {
// 用户授权成功后,开始连接WiFi
this.startWifi();
},
fail: () => {
uni.showToast({
title: '位置信息授权失败',
icon: 'none'
});
}
});
},
// 开启WiFi模块
startWifi() {
uni.startWifi({
success: (success) => {
console.log("success", success)
this.detectionWifi();
},
fail: (err) => {
console.log("开启WiFi模块失败", err);
// 开启WiFi模块失败后的处理逻辑
}
});
},
//