今天我分享另外一种方法。请看下面.gif;
有没有发现,左上角有返回按钮了。原理简单,在你要分享的页面,分享配置时配置你的首页,并带上对应的参数,在首页 onload方法中可以获取。代码如下:
<!--index.wxml--> <view class="container"> <text>我是首页</text> <button bindtap='gologs'>go logspage</button> </view> const app = getapp() page({ data: { motto: 'hello world', userinfo: {}, hasuserinfo: false, caniuse: wx.caniuse('button.open-type.getuserinfo') }, //事件处理函数 gologs: function() { wx.navigateto({ url: '/pages/logs/logs' }) }, onload: function (options) { console.log(options) if (options.share_query){ wx.showloading({ title: '我是从分享页面进入的', }) settimeout(function () { wx.hideloading() wx.navigateto({ url: '/pages/logs/logs', }) }, 2000) } } }) <!--logs.wxml--> <view class="container log-list"> <block wx:for="{{logs}}" wx:for-item="log"> <text class="log-item">{{index + 1}}. {{log}}</text> </block> </view> const app = getapp() page({ data: { motto: 'hello world', userinfo: {}, hasuserinfo: false, caniuse: wx.caniuse('button.open-type.getuserinfo') }, //事件处理函数 gologs: function() { wx.navigateto({ url: '/pages/logs/logs' }) }, onload: function (options) { console.log(options) //判断是否分享进入 if (options.share_query){ wx.showloading({ title: '我是从分享页面进入的', }) settimeout(function () { wx.hideloading() wx.navigateto({ url: '/pages/logs/logs', }) }, 2000) } } })
以上就是微信小程序之如何返回首页的详细内容。
