WeChat Mini Program-Click the button to exit the Mini Program solution (and incompatible solutions)

Preface

Sometimes, when the user clicks the button to exit the applet , rather than by the user clicking the top right corner 小程序胶囊to close.

Program

Official document: https://developers.weixin.qq.com/miniprogram/dev/component/navigator.html

Direct use of <navigator>components can, specific code as follows:

<navigator open-type="exit" target="miniProgram">关闭小程序</navigator>

Precautions

You may have an incompatibility problem.

When this feature is the minimum supported version 2.1.0, if you must use this feature, it is best to set the minimum basic library version in the applet management background to be no lower than that 2.1.0.

If the minimum basic library supported by the applet is lower than the 2.1.0basic library version of the applet, the version of the applet basic library can be judged. If the applet is supported, the exit component will be used. If it is not supported, then the compatibility processing of jumping to other specified pages will be done. .

wx.getSystemInfo({
    
    
 success: function(res) {
    
    
  if(res.SDKVersion>="2.1.0"){
    
    
   self.setData({
    
    
   exitApp:true//data中的初始化变量
   })
  }
 }
})
<navigator wx:if="{
     
     {exitApp}}" open-type="exit" target="miniProgram">关闭按钮</navigator>
 <navigator wx:else open-type="navigate" target="navigate" url='../../index/index'>返回首页</navigator>

If it's the homepage, then just don't process this return and exit.

Note: because it is not API, we can not use wx.canIUse(string)the way of judgment, and we can only get a small code base library information system by procuring the way, in order to determine.

Guess you like

Origin blog.csdn.net/weixin_44198965/article/details/108912117