index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { use } from '../utils';
  2. var _use = use('tabbar'),
  3. sfc = _use[0],
  4. bem = _use[1];
  5. export default sfc({
  6. data: function data() {
  7. return {
  8. items: []
  9. };
  10. },
  11. props: {
  12. value: Number,
  13. activeColor: String,
  14. safeAreaInsetBottom: Boolean,
  15. fixed: {
  16. type: Boolean,
  17. "default": true
  18. },
  19. zIndex: {
  20. type: Number,
  21. "default": 1
  22. }
  23. },
  24. watch: {
  25. items: function items() {
  26. this.setActiveItem();
  27. },
  28. value: function value() {
  29. this.setActiveItem();
  30. }
  31. },
  32. methods: {
  33. setActiveItem: function setActiveItem() {
  34. var _this = this;
  35. this.items.forEach(function (item, index) {
  36. item.active = index === _this.value;
  37. });
  38. },
  39. onChange: function onChange(active) {
  40. if (active !== this.value) {
  41. this.$emit('input', active);
  42. this.$emit('change', active);
  43. }
  44. }
  45. },
  46. render: function render(h) {
  47. return h("div", {
  48. "style": {
  49. zIndex: this.zIndex
  50. },
  51. "class": ['van-hairline--top-bottom', bem({
  52. fixed: this.fixed,
  53. 'safe-area-inset-bottom': this.safeAreaInsetBottom
  54. })]
  55. }, [this.slots()]);
  56. }
  57. });