back.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <view class="back" :style="{height: capsuleHeight+ 'px',top:capsuleHighly+'px'}">
  3. <u-icon name="arrow-left" v-if="show" :color="color" size="24" @click="backIconHandler"></u-icon>
  4. <u-icon name="home-fill" v-if="!show" :color="color" size="24" @click="backHomeHandler"></u-icon>
  5. <view class="back-text" :style="{color: color}">
  6. {{ text }}
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. name: "back",
  13. props:{
  14. text:{
  15. type:String,
  16. default:''
  17. },
  18. color:{
  19. type:String,
  20. default:'#3B4144'
  21. },
  22. show:{
  23. type:Boolean,
  24. default: true
  25. }
  26. },
  27. data() {
  28. return {
  29. //胶囊高度
  30. capsuleHeight: 0,
  31. //
  32. capsuleHighly: 0,
  33. };
  34. },
  35. created() {
  36. this.getCapsuleSite()
  37. },
  38. methods:{
  39. backIconHandler(){
  40. uni.navigateBack()
  41. },
  42. backHomeHandler(){
  43. uni.switchTab({
  44. url: '/pages/home/home'
  45. })
  46. },
  47. //获取胶囊位置信息
  48. getCapsuleSite(){
  49. let res=uni.getMenuButtonBoundingClientRect()
  50. this.capsuleHeight = res.height
  51. this.capsuleHighly = res.top
  52. }
  53. }
  54. }
  55. </script>
  56. <style lang="scss">
  57. .back {
  58. position: relative;
  59. padding: 0 0 120rpx 20rpx;
  60. display: flex;
  61. align-items: center;
  62. z-index: 99;
  63. .t-icon {
  64. width: 35rpx;
  65. height: 35rpx;
  66. }
  67. .back-text{
  68. font-size: 40rpx;
  69. font-weight: bold;
  70. margin:0 0 6rpx 20rpx;
  71. }
  72. }
  73. </style>