uniapp退出关闭当前小程序或APP的简单实现

需求:
1.点击按钮主动退出微信小程序(后台也退出)
2.满足条件触发主动退出微信小程序事件(后台也退出)

  • 方法1:----------按钮退出
<!--此方法只需要在wxml里添加下面代码即可,无需用 bindtap关联函数-->
<navigator target="miniProgram" open-type="exit">
   <button plain="true">退出登录</button>
</navigator>
  • 方法2:---------函数退出

通过在函数内部调用微信提供的API实现退出小程序,配置项包含成功和失败的回调函数:

uni.exitMiniProgram({
	success: function() {
		console.log('退出小程序成功');
	},
	fail: function(err) {
		console.log('退出小程序失败', err);
	}
})

猜你喜欢

转载自blog.csdn.net/peachban/article/details/134239107
今日推荐