微信小程序实现关闭功能

摘自简书ThinkinLiu,推荐大家去看原作者的文章。

微信小程序API内是不提供关闭小程序的按钮的,但是我们可以通过页面跳转的方式,关闭微信小程序。

微信小程序退出

test.wxml:

<view>
    <view bindtap="close">关闭</view>
</view>

test.js:

close: function(e){
    // @simorel
    // 2018年8月6日 10点21分
    // 跳转至 check 页面,带着参数 finish 为true
    wx.navigateTo({ url: 'check?finish=true' });
}

/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
    // @simorel
    // 2018年8月6日 10点22分
    // 退出微信小程序
    if (options.finish) {
      wx.navigateBack({ delta: 1 })
    }
}

猜你喜欢

转载自blog.csdn.net/Simoral/article/details/81450167