index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. classes: ['title-class'],
  4. props: {
  5. title: String,
  6. fixed: {
  7. type: Boolean,
  8. observer: 'setHeight'
  9. },
  10. placeholder: {
  11. type: Boolean,
  12. observer: 'setHeight'
  13. },
  14. leftText: String,
  15. rightText: String,
  16. leftArrow: Boolean,
  17. border: {
  18. type: Boolean,
  19. value: true
  20. },
  21. zIndex: {
  22. type: Number,
  23. value: 1
  24. },
  25. safeAreaInsetTop: {
  26. type: Boolean,
  27. value: true
  28. }
  29. },
  30. data: {
  31. statusBarHeight: 0,
  32. height: 44
  33. },
  34. created() {
  35. const { statusBarHeight } = wx.getSystemInfoSync();
  36. this.setData({
  37. statusBarHeight,
  38. height: 44 + statusBarHeight
  39. });
  40. },
  41. mounted() {
  42. this.setHeight();
  43. },
  44. methods: {
  45. onClickLeft() {
  46. this.$emit('click-left');
  47. },
  48. onClickRight() {
  49. this.$emit('click-right');
  50. },
  51. setHeight() {
  52. if (!this.data.fixed || !this.data.placeholder) {
  53. return;
  54. }
  55. wx.nextTick(() => {
  56. this.getRect('.van-nav-bar').then((res) => {
  57. this.setData({ height: res.height });
  58. });
  59. });
  60. }
  61. }
  62. });