评论

页面跳转封装

对页面跳转的二次封装

export default (options, type = 1) => {
return new Promise((reslove, reject) => {
routes[type](Object.assign(getPath(options), {
success: reslove,
fail: reject,
}));
});
};

function getPath(options) {
switch (Reflect.toString.call(options)) {
case “[object Object]”:
return {
url: ${options.url}?data=${encodeURIComponent(JSON.stringify(options.data))},
};
case “[object Number]”:
return {
delta: options,
};
case “[object String]”:
return {
url: options,
};
}
}

const routes = {
1: wx.navigateTo,
2: wx.switchTab,
3: wx.navigateBack,
4: wx.reLaunch,
5: wx.redirectTo,
};

点赞 0
收藏
评论
登录 后发表内容