refreshCurrent.js 545 B

123456789101112131415161718192021
  1. // 将对象序列化为查询字符串
  2. function stringifyQuery(obj) {
  3. let ret = [];
  4. for (let key in obj) {
  5. if (obj.hasOwnProperty(key)) {
  6. ret.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]));
  7. }
  8. }
  9. return ret.join('&');
  10. }
  11. export function refreshCurrentPage() {
  12. // 获取当前页面的路径
  13. let currentPage = getCurrentPages().pop();
  14. if (currentPage) {
  15. // 重启当前页面
  16. uni.reLaunch({
  17. url: `/${currentPage.route}` + (currentPage.options ? `?${stringifyQuery(currentPage.options)}` :
  18. '')
  19. });
  20. }
  21. }