index.vue 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <uni-shadow-root class="vant-sidebar-item-index"><view :class="(utils.bem('sidebar-item', { selected, disabled }))+' '+(selected ? 'active-class' : '')+' '+(disabled ? 'disabled-class' : '')+' custom-class'" hover-class="van-sidebar-item--hover" hover-stay-time="70" @click="onClick">
  3. <view class="van-sidebar-item__text">
  4. <van-info v-if="badge != null || info !== null || dot" :dot="dot" :info="badge != null ? badge : info"></van-info>
  5. <view v-if="title">{{ title }}</view>
  6. <slot v-else name="title"></slot>
  7. </view>
  8. </view></uni-shadow-root>
  9. </template>
  10. <wxs src="../wxs/utils.wxs" module="utils"></wxs>
  11. <script>
  12. import VanInfo from '../info/index.vue'
  13. global['__wxVueOptions'] = {components:{'van-info': VanInfo}}
  14. global['__wxRoute'] = 'vant/sidebar-item/index'
  15. import { VantComponent } from '../common/component';
  16. import { useParent } from '../common/relation';
  17. VantComponent({
  18. classes: ['active-class', 'disabled-class'],
  19. relation: useParent('sidebar'),
  20. props: {
  21. dot: Boolean,
  22. badge: null,
  23. info: null,
  24. title: String,
  25. disabled: Boolean,
  26. },
  27. methods: {
  28. onClick() {
  29. const { parent } = this;
  30. if (!parent || this.data.disabled) {
  31. return;
  32. }
  33. const index = parent.children.indexOf(this);
  34. parent.setActive(index).then(() => {
  35. this.$emit('click', index);
  36. parent.$emit('change', index);
  37. });
  38. },
  39. setActive(selected) {
  40. return this.setData({ selected });
  41. },
  42. },
  43. });
  44. export default global['__wxComponents']['vant/sidebar-item/index']
  45. </script>
  46. <style platform="mp-weixin">
  47. @import '../common/index.css';.van-sidebar-item{background-color:var(--sidebar-background-color,#f7f8fa);border-left:3px solid transparent;box-sizing:border-box;color:var(--sidebar-text-color,#323233);display:block;font-size:var(--sidebar-font-size,14px);line-height:var(--sidebar-line-height,20px);overflow:hidden;padding:var(--sidebar-padding,20px 12px 20px 8px);-webkit-user-select:none;user-select:none}.van-sidebar-item__text{display:inline-block;position:relative;word-break:break-all}.van-sidebar-item--hover:not(.van-sidebar-item--disabled){background-color:var(--sidebar-active-color,#f2f3f5)}.van-sidebar-item:after{border-bottom-width:1px}.van-sidebar-item--selected{border-color:var(--sidebar-selected-border-color,#ee0a24);color:var(--sidebar-selected-text-color,#323233);font-weight:var(--sidebar-selected-font-weight,500)}.van-sidebar-item--selected:after{border-right-width:1px}.van-sidebar-item--selected,.van-sidebar-item--selected.van-sidebar-item--hover{background-color:var(--sidebar-selected-background-color,#fff)}.van-sidebar-item--disabled{color:var(--sidebar-disabled-text-color,#c8c9cc)}
  48. </style>