Sidebar.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div>
  3. <ul class="sidebar">
  4. <li @click="handleItem(item)" :class="{active:item.id==activeId}" v-for="(item,i) in list" :key="i">{{item.title}}</li>
  5. </ul>
  6. <slot name="bottom"></slot>
  7. </div>
  8. </template>
  9. <script>
  10. export default {
  11. props:{
  12. list:{
  13. type:Array,
  14. default:()=>{
  15. return []
  16. }
  17. },
  18. activeId:{
  19. type:String,
  20. default:''
  21. }
  22. },
  23. methods:{
  24. handleItem(item){
  25. this.$emit('handleItem',item)
  26. }
  27. }
  28. }
  29. </script>
  30. <style lang="less" scoped>
  31. .sidebar{
  32. border: 1px solid #9E9E9E;
  33. max-width: 250px;
  34. min-width: 220px;
  35. li{
  36. overflow: hidden;
  37. text-overflow:ellipsis;
  38. white-space: nowrap;
  39. line-height: 50px;
  40. height: 50px;
  41. padding: 0 10px 0 24px;
  42. position: relative;
  43. cursor: pointer;
  44. color: #9e9e9e;
  45. text-align: left;
  46. &::before{
  47. display: inline-block;
  48. content: '';
  49. width: 4px;
  50. height: 4px;
  51. position: absolute;
  52. transform: translate(-50%,-50%);
  53. left: 18px;
  54. top: 50%;
  55. border-radius: 50%;
  56. background-color: #9e9e9e;
  57. }
  58. &:hover{
  59. &::before{
  60. background-color: #fff;
  61. }
  62. }
  63. }
  64. .active{
  65. font-weight: bold;
  66. &::before{
  67. background-color: #fff;
  68. }
  69. }
  70. }
  71. </style>