back.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <view class="page">
  3. <view class="flex-sub">
  4. <view class="back " @click="back()">
  5. <text class="cuIcon-back" style="color: #FFFFFF;"></text>
  6. </view>
  7. </view>
  8. <view class="title flex-sub" v-if="title">
  9. <text :style="titleStyle">{{title}}</text>
  10. </view>
  11. <view class="flex-sub">
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. name: "back",
  18. props: {
  19. title: {
  20. type: String,
  21. default: ''
  22. },
  23. titleStyle: {
  24. type: String,
  25. default: 'color: #fff;font-size: 32rpx;'
  26. },
  27. customBack: {
  28. type: Function,
  29. default: null
  30. }
  31. },
  32. data() {
  33. return {
  34. };
  35. },
  36. methods: {
  37. back() {
  38. // 如果自定义了点击返回按钮的函数,则执行,否则执行返回逻辑
  39. if (typeof this.customBack === 'function') {
  40. this.customBack.bind(this.$u.$parent.call(this))();
  41. } else {
  42. uni.navigateBack();
  43. }
  44. uni.navigateBack({
  45. delta: 1
  46. })
  47. },
  48. }
  49. }
  50. </script>
  51. <style lang="scss" scoped>
  52. .flex-sub {
  53. flex: 1;
  54. }
  55. .title {
  56. text-align: center;
  57. display: flex;
  58. justify-content: center;
  59. align-items: center;
  60. }
  61. .page {
  62. position: fixed;
  63. width: 100%;
  64. top: var(--status-bar-height);
  65. margin-top: var(--status-bar-height);
  66. z-index: 9999999999;
  67. transition: top .25s;
  68. display: flex;
  69. width: 100%;
  70. }
  71. .back {
  72. margin-left: 20rpx;
  73. width: 60rpx;
  74. height: 60rpx;
  75. border-radius: 50%;
  76. background-color: rgba(0, 0, 0, .2);
  77. display: flex;
  78. justify-content: center;
  79. align-items: center;
  80. }
  81. </style>