uniapp常用方法内容

//在起始页面跳转到test.vue页面并传递参数

uni.navigateTo({
    
    
    url: 'test?id=1&name=uniapp'
});

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

uni.redirectTo({
    
    
    url: 'test?id=1'
});
关闭所有页面,打开到应用内的某个页面
uni.reLaunch({
    
    
    url: 'test?id=1'
});

跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面。

uni.switchTab({
    
    
    url: '/pages/index/index'
});

关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages() 获取当前的页面栈,决定需要返回几层。

uni.navigateBack({
    
    
    delta: 2
});

将数据存储在本地缓存中指定的 key 中,会覆盖掉原来该 key 对应的内容,这是一个异步接口。

uni.setStorage({
    
    
    key: 'storage_key',
    data: 'hello',
    success: function () {
    
    
        console.log('success');
    }
});

显示消息提示框。

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

uni.hideToast() 隐藏消息提示框。
在这里插入图片描述
显示模态弹窗,类似于标准 html 的消息框:alert、confirm。

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

猜你喜欢

转载自blog.csdn.net/qq_45432996/article/details/112550092
今日推荐