uniapp小程序知识梳理

一、跳转页面

// 一、简单参数:
uni.navigateTo({
	url:'/pagesMine/sellerCard/index?merchantId='+item.id
})

// 二、多个参数:
uni.navigateTo({ url: `/pagesMine/myCard/index?cardId=${item.cardId}&merchantId=${item.merchantId}` })


三、复杂参数/对象:
uni.navigateTo({ url: '/pagesMine/cardCode/index?params='+ encodeURIComponent(JSON.stringify(this.codeInfo)) })

// 注:需要在唉跳转后的页面onLoad(option)中去接收,当参数是对象时,需要先解析

二、关闭当前页面,跳转到应用内的某个页面

uni.redirectTo({
	url:this.urls?`/pages/login/login_name?urls=${this.urls}&type=2`:'/pages/login/login_name?type=2'
})

三、返回上一页(延迟1.5s再返回)

setTimeout(()=> {
   uni.navigateBack()
   this.$forceUpdate()
},1500)

四、设置页面头部标题

uni.setNavigationBarTitle({
	title: this.title
});
// 注:这里需要注意调用的位置

五、存入通讯录

uni.addPhoneContact({
      	nickName: this.sellerCard.cardName,
      	lastName: this.sellerCard.cardName.slice(0,1),
      	firstName: this.sellerCard.cardName.slice(1),
      	remark: '',
      	mobilePhoneNumber: this.sellerCard.cardMobile,
      	weChatNumber: this.sellerCard.cardWeChat,
      	success: function () {
      		console.log('success');
      	},
      	fail: function (err) {
          if(err.errMsg === 'addPhoneContact:fail auth deny'){ //没权限
            uni.showModal({
              title: '“APP”想访问您的手机通讯录',
              content: '为了快捷的存入手机号到您的通讯录中, 需要开启APP的手机通讯录权限。',
              success: function (res) {
                if (res.confirm) {
                  uni.openSetting({
                    success(res) {
                      console.log(res.authSetting)
                    }
                  });
                } else if (res.cancel) {
                  console.log('用户点击取消');
                }
              }
            });
          }
      	}
});

//注:这里做了一个优化,IOS系统在手动拒绝,再次点击“存入通讯录”没有反应,需要手动去开启权限,这里在失败后的信息中做了判断提示

六、拨打电话

uni.makePhoneCall({
	phoneNumber: this.sellerCard.cardMobile
});
// 注:这里的数据类型需要是String类型

七、获取缓存信息

uni.getStorageSync('buy_token')

八、清除缓存

// 买家小程序中清除缓存:
uni.removeStorageSync('otherSwitchTab')
// 注:这里需要放在onShow中

九、获取微信胶囊高度:

//获取微信胶囊的高度
export function getJnHeight() {
	let res = uni.getMenuButtonBoundingClientRect();
	return res.height
}
// 注:需要放在js文件中,然后再暴露出去

十、提示弹窗

uni.showToast({
	title: '标题',
	duration: 2000
});

十一、加载中提示

uni.showLoading({
	title: '加载中'
});

十二、隐藏 loading 提示框

setTimeout(function () {
	uni.hideLoading();
}, 2000);

十三、显示模态弹窗

uni.showModal({
	title: '提示',
	content: '这是一个模态弹窗',
	success: function (res) {
		if (res.confirm) {
			console.log('用户点击确定');
		} else if (res.cancel) {
			console.log('用户点击取消');
		}
	}
});

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值