1.0.8 • Published 3 years ago
@miapp/utils v1.0.8
utils
工具集
使用
import {
// type
typeOf,
isNull,
isUndefined,
isNumber,
isDate,
isRegExp,
isArray,
isObject,
isString,
isFunction,
isBoolean,
isValue,
// object
forEach,
mix,
merge,
clone,
// data
getData,
setData,
ellipsis,
tryParse,
escapeHTML,
paramsToObj,
objToParams,
simpleDeepCompare,
// params
parseURL,
getParams,
getLaunchOptions,
initParams,
initLaunchOptions,
getUrlParam,
setUrlParam,
deleteUrlParam,
// navigate
open,
close
} from "@miapp/utils";
// type
typeOf({}); // object
isArray([]); // true
// data
const data = { a: { b: { c: 1 } } };
getData(data, 'a.b.c'); // 1
setData(data, 'a.b.c', 2); // 2
paramsToObj('a=1&b=2'); // { a: '1', b: '2' }
objToParams({ a: 1, b: 2 }); // a=1&b=2
// object
forEach(obj, (v, k) => console.log(v));
forEach(arr, (v, i) => console.log(v));
mix(obj1, obj2); // mix obj2 into obj1
merge(obj1, obj2); // return a new object
merge(obj1, obj2, obj3, true); // including undefined
clone(obj); // clone a new object
// params
const href = 'https://m.taobao.com?a=1&b=2&c=true';
getUrlParam(href); // like getParam()
getUrlParam(href, 'a'); // like getParam('a')
setUrlParam(href, 'a', 6); // https://m.taobao.com?a=6&b=2&c=true
setUrlParam(href, { a: 6, c: null }); // https://m.taobao.com?a=6&b=2
deleteUrlParam(href, 'a'); // https://m.taobao.com?b=2&c=true
App({
onLaunch(opts) {
initLaunchOptions(this, opts);
}
})
// 页面
Page({
onLoad(query) {
initParams(this, query); // 初始化页面参数
}
});
// 组件
Component({
didMount() {
const params = getParams(this); // { a: '1', b: '2', c: 'true' }
const launchOpts = getLaunchOptions(this);
}
})
// navigate
// https://m.taobao.com
close();
open(url);
open(url, { params: { a: 1, b: 2 } });
// 相对路径兼容小程序不带后缀
open('/pages/detail/index?a=1');
open('../detail/index');
// 数据回传
open(url, { backListener: data => console.log(data) }); // 前一个页面
close({ data: { a: 1, b: 2 } }); // 后一个页面
// 小程序跳转 webview 页面
open(url, { webview: true }); // /pages/webview/index?url=encodeURIComponent(url)
开发
更多命令
miapp newbranch
: 新建分支miapp push
: 提交代码miapp prepub
: 预发(发布 beta 版本)miapp publish
: 正式发布
1.0.8
3 years ago
1.0.7
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.5-beta.0
4 years ago
1.0.4-beta.0
4 years ago
1.0.3-beta.0
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.2
4 years ago
1.0.2-beta.0
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago
1.0.1-beta.0
4 years ago
1.0.0-beta.0
4 years ago