MHeader.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <div class="mheader">
  3. <header class="m-nav-header" :class="[isFixed ? 'fixed' : '']">
  4. <div class="m-nav-bar__left" @click="goBack" v-show="isBack">
  5. <van-icon class="arrow-left" name="arrow-left"></van-icon>
  6. </div>
  7. <div class="m-nav-bar__title">
  8. <slot>{{ name ? name : $route.meta.descrition }}</slot>
  9. </div>
  10. <div class="m-nav-bar__right">
  11. <slot name="right"></slot>
  12. </div>
  13. </header>
  14. </div>
  15. </template>
  16. <script>
  17. /**
  18. * 插槽使用方式
  19. * <template v-slot:right>
  20. 这里
  21. </template>
  22. */
  23. export default {
  24. name: "mheader",
  25. props: {
  26. name: String, // 标题名称
  27. isBack: {
  28. // 是否显示返回按钮
  29. type: Boolean,
  30. default: true,
  31. },
  32. isFixed: {
  33. // 是否固定顶部
  34. type: Boolean,
  35. default: true,
  36. },
  37. backUrl: {
  38. // 跳转指定的URL
  39. type: Object,
  40. default: () => {
  41. return {
  42. callBack: null, // 方法
  43. path: "", // 跳转路径
  44. params: {}, // 跳转参数 目前只能用query的方式
  45. };
  46. },
  47. },
  48. },
  49. methods: {
  50. goBack() {
  51. // 返回上层
  52. let urlObj = this.backUrl;
  53. // console.log(typeof urlObj.callBack)
  54. if (typeof urlObj.callBack == "function") {
  55. urlObj.callBack();
  56. } else {
  57. if (urlObj.path) {
  58. this.$router.push({
  59. path: urlObj.path,
  60. query: urlObj.params,
  61. });
  62. } else {
  63. history.go(-1);
  64. }
  65. }
  66. },
  67. },
  68. };
  69. </script>
  70. <style lang="less" scoped>
  71. @import url("../assets/commonLess/variable");
  72. .mheader {
  73. height: 0.46rem;
  74. overflow: hidden;
  75. }
  76. .m-nav-header {
  77. position: absolute;
  78. left: 0;
  79. top: 0;
  80. width: 100%;
  81. height: 0.46rem;
  82. line-height: 0.46rem;
  83. background-color: @whiteColor;
  84. text-align: center;
  85. user-select: none;
  86. color: @blackColor;
  87. &.fixed {
  88. position: fixed;
  89. z-index: 99;
  90. }
  91. .m-nav-bar__title {
  92. max-width: 60%;
  93. margin: 0 auto;
  94. color: @blackColor;
  95. font-weight: 500;
  96. font-size: 0.16rem;
  97. }
  98. .m-nav-bar__left,
  99. .m-nav-bar__right {
  100. position: absolute;
  101. bottom: 0;
  102. }
  103. .m-nav-bar__left {
  104. left: 0.12rem;
  105. .arrow-left {
  106. font-size: 0.21rem;
  107. vertical-align: middle;
  108. }
  109. }
  110. .m-nav-bar__right {
  111. right: 0.12rem;
  112. }
  113. }
  114. </style>