Uni-app 常用代码

提示信息

uni.showToast({
  title: '提示信息',
  duration: 2000
});

页面跳转

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

// 延时2秒后退
setTimeout(() => {
  uni.navigateBack({delta: 1});
}, 2000);

缓存相关

uni.setStorageSync('key', val)
uni.getStorageSync('key')
uni.removeStorageSync('key')

// sessionStorage 的基本使用
sessionStorage.setItem("key", val);
let data = sessionStorage.getItem('key');
sessionStorage.removeItem('key');

// sessionStorage 存储数组对象
var obj = { name:'Antto' };
sessionStorage.obj = JSON.stringify(obj);
var obj2 = JSON.parse(sessionStorage.obj);
console.log(obj2);

172 total views, 2 views today

Revisions

Comments are closed.