一、跳转页面
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)) })
二、关闭当前页面,跳转到应用内的某个页面
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('用户点击取消');
}
}
});
}
}
});
六、拨打电话
uni.makePhoneCall({
phoneNumber: this.sellerCard.cardMobile
});
七、获取缓存信息
uni.getStorageSync('buy_token')
八、清除缓存
uni.removeStorageSync('otherSwitchTab')
九、获取微信胶囊高度:
export function getJnHeight() {
let res = uni.getMenuButtonBoundingClientRect();
return res.height
}
十、提示弹窗
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('用户点击取消');
}
}
});