微信小程序 App.js 公共方法 小功能

10 篇文章 0 订阅
3 篇文章 0 订阅

微信小程序 App.js 公共方法 小功能

微信小程序 App.js 公共方法 小功能 // 原生开发微信小程序 //

路由跳转

goto: function(url) {
	wx.navigateTo({
	  url: url,
	  fail: () => {
	    wx.switchTab({
	      url: url,
	    })
	  }
	})
},

//调用该方法
<view bindtap="goto" data-url="/pages/index/details/details" data-id="1" ></view>

const app = getApp();

goto: function(e) {
	var url = e.currentTarget.dataset.url;
	var id = e.currentTarget.dataset.id;
	var type = e.currentTarget.dataset.type;
	var urlid = url + '?id=' + id + '&type=' + type;
	app.goto(urlid);
},

弹窗提示

errorTip: function(that, text, timer) {
	wx.showToast({
	  title: text,
	  icon: 'none',
	  duration: timer
	})
},

//调用该方法
app.errorTip(that, 弹窗内容, 2000);

判断登录状态

getUserInfo: function(cb) {
	var that = this;
	if (wx.getStorageSync('logintag')) {
	  typeof cb == "function" && cb(this.globalData.userInfo)
	} else {
	  // wx.switchTab({
	  //   url: '/pages/log/log',
	  // })
	  wx.redirectTo({
	    url: '/pages/log/log',
	  });
	  console.log('app logintag为空....... 重新获取');
	}
},

//调用该方法
var that = this;
app.getUserInfo(that.membercenter());

//需要调用方法
membercenter:function(){

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值