在微信小程序api中有這樣一個組件
navigator: 頁面鏈接
open-type | string | navigate | 否 | 跳轉方式 |
open-type 的合法值
值 | 說明 | 最低版本 |
---|---|---|
navigate | 對應 wx.navigateTo 或 wx.navigateToMiniProgram 的功能 | |
redirect | 對應 wx.redirectTo 的功能 | |
switchTab | 對應 wx.switchTab 的功能 | |
reLaunch | 對應 wx.reLaunch 的功能 | 1.1.0 |
navigateBack | 對應 wx.navigateBack 的功能 | 1.1.0 |
exit | 退出小程序,target="miniProgram" 時生效 |
2.1.0 |
上面是微信小程序官方給的文檔
然后再來看我們的代碼如何實現其實很簡單就一行代碼
<navigator id="submitBtn" class="ui-btn" open-type="exit" target="miniProgram" style="left:100px;" bindtap="out" > 點此退出 </navigator>
只要在wxml中在的navigator中加上屬性open-type="exit"並且需要加上 target="miniProgram"點擊一下就會直接強制退出才會生效