我这也遇上这个问题了,看了上面两位奆佬的解答才知道为啥,我这用的解决方法是设置button的open-type="{{weizhi}}",在fail后设置setData里的weizhi变成openSetting,感觉不是很好,权当抛砖引玉吧。
openSetting()的问题,我用了打不开设置?关于为了避免用户取消“获取地址”之后无法再打开,我看教程说是用opensetting(). https://www.bilibili.com/video/BV1y7411z7hQ?p=85 但是代码一样还是没用。我用openSetting()怎么还打不开设置,不知道哪错了. 点取消授权,再点button, console确实输出我故意打印的“取消”了但并没有打开设置。 WXML: 获取收货地址 JS. handleChooseAddress(){ wx.getSetting({ success: (result) => { // console.log(result); const scopeAddress=result.authSetting["scope.address"]; if (scopeAddress===true||scopeAddress===undefined){ //console.log(result); wx.chooseAddress({ success: (result1) => { console.log(result1); } }); }else{ console.log("取消"); wx.openSetting({ success: (result2) => { wx.chooseAddress({ success: (result3) => { console.log(result3); } }); } }); } } }) } 另一种写法还是不对 : 报错:errMsg: "openSetting:fail errcode 1"} /* Promise形式 getSetting */ export const getSetting=()=>{ return new Promise((resolve,reject)=>{ wx.getSetting({ withSubscriptions: true, success: (result)=>{ resolve(result); }, fail:(err)=>{ reject(err); } }); }) } /* Promise形式 chooseAddress */ export const chooseAddress=()=>{ return new Promise((resolve,reject)=>{ wx.chooseAddress({ withSubscriptions: true, success: (result)=>{ resolve(result); }, fail:(err)=>{ reject(err); } }); }) } /* Promise形式 openSetting */ export const openSetting=()=>{ return new Promise((resolve,reject)=>{ wx.openSetting({ withSubscriptions: true, success: (result)=>{ resolve(result); }, fail:(err)=>{ reject(err); } }); }) } // pages/cart/index.js import{getSetting,chooseAddress,openSetting } from "../../utils/asyncWx.js"; import regeneratorRuntime from '../../lib/runtime/runtime'; Page({ /** * 页面的初始数据 */ data: { }, async handleChooseAddress(){ try { /* wx.getSetting({ success: (result) => { // console.log(result); const scopeAddress=result.authSetting["scope.address"]; if (scopeAddress===true||scopeAddress===undefined){ //console.log(result); wx.chooseAddress({ success: (result1) => { console.log(result1); } }); }else{ console.log("取消"); wx.openSetting({ success: (result2) => { wx.chooseAddress({ success: (result3) => { console.log(result3); } }); } }); } }, fail:()=>{}, complete:()=>{} }); */ const res1=await getSetting(); const scopeAddress=res1.authSetting["scope.address"]; if (scopeAddress===false){ await openSetting(); } const res2=await chooseAddress(); console.log(res2); } catch (error) { console.log(error); } } })
2020-08-16