时空网前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.3 KiB

4 years ago
  1. <template>
  2. <view></view>
  3. </template>
  4. <script>
  5. /* 路由分发页面仅供跳转页面 */
  6. export default {
  7. onLoad(options){
  8. this.routeToPage(options);
  9. },
  10. methods: {
  11. // 路由分发
  12. routeToPage(options){
  13. if(options.route == 'goods_detail'){
  14. options.page_url = '/pages/goodsDetail/index';
  15. this.joinPagePath(options);
  16. }else if(options.route == 'home'){
  17. options.page_url = '/pages/index/index';
  18. options.is_tabbar = true; // 是否为tabbar,如果是需要多传入该参数
  19. this.joinPagePath(options);
  20. }else{
  21. let obj = {
  22. page_url: '/pages/index/index', // 啥都不填,默认跳转到首页
  23. is_tabbar: true
  24. };
  25. this.joinPagePath(obj);
  26. }
  27. },
  28. // 拼接地址,并相应跳转
  29. joinPagePath(par){
  30. let path = par.page_url;
  31. let flag = true; // 标志,用于判断拼接次数,?只能出现一次
  32. for(let i in par){
  33. if(i != 'route' && i != 'page_url' && i != 'is_tabbar'){ // 跳过route、page_url、is_tabbar
  34. if(flag){
  35. path += '?'+ i +'='+ par[i];
  36. flag = false;
  37. }else{
  38. path += '&'+ i +'='+ par[i];
  39. }
  40. }
  41. }
  42. if(par.is_tabbar){
  43. this.$url(path, {type: 'switch'});
  44. }else{
  45. this.$url(path, {type: 'redirect'});
  46. }
  47. }
  48. }
  49. }
  50. </script>