Slider.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <main>
  3. <header @click="handleClick(-1)">
  4. <img src="@/assets/slider/logo.svg" />
  5. </header>
  6. <section>
  7. <div v-for="(item, key) in slider" :key="key" @click="handleClick(key)" :class="{ active: key === index }">
  8. <div>
  9. <img :src="getAssetURL(`/src/assets/slider/${item.icon}.svg`)" width="24" class="img-normal" />
  10. <img :src="getAssetURL(`/src/assets/slider/${item.icon}-1.svg`)" width="24" class="img-hover" />
  11. <p>{{ item.title }}</p>
  12. </div>
  13. </div>
  14. </section>
  15. <footer>
  16. <div style="background-color: rgb(255, 110, 110)">{{ userName.slice(0, 1) }}</div>
  17. <p>{{ userName }}</p>
  18. </footer>
  19. </main>
  20. </template>
  21. <script>
  22. import { defineComponent, inject, onMounted, ref } from "vue";
  23. export default defineComponent({
  24. props: ["index"],
  25. setup(props, { emit }) {
  26. const { helper, config } = inject("$global");
  27. const userName = ref("vickeryvickeryvickery");
  28. const handleClick = (index) => {
  29. emit("select-nav", index);
  30. };
  31. return {
  32. slider: config.slider,
  33. getAssetURL: helper.getAssetURL,
  34. userName,
  35. handleClick
  36. };
  37. }
  38. });
  39. </script>
  40. <style lang="scss" scoped>
  41. main {
  42. padding: 20px 0;
  43. width: 100px;
  44. border-right: 1px solid rgba(0, 0, 0, 0.1);
  45. display: flex;
  46. flex-direction: column;
  47. > header {
  48. cursor: pointer;
  49. > img {
  50. display: block;
  51. width: 62px;
  52. margin: 0 auto;
  53. }
  54. }
  55. > section {
  56. flex: 1;
  57. margin-top: 27px;
  58. > div {
  59. margin: 0 auto;
  60. width: 70px;
  61. height: 70px;
  62. border-radius: 8px;
  63. cursor: pointer;
  64. display: flex;
  65. align-items: center;
  66. justify-content: center;
  67. .img-normal {
  68. display: block;
  69. }
  70. .img-hover {
  71. display: none;
  72. }
  73. &:hover,
  74. &.active {
  75. background: rgba(0, 0, 0, 0.05);
  76. .img-normal {
  77. display: none;
  78. }
  79. .img-hover {
  80. display: block;
  81. }
  82. }
  83. img {
  84. display: block;
  85. margin: 0 auto;
  86. }
  87. p {
  88. font-size: 13px;
  89. margin-top: 2px;
  90. color: rgb(51, 51, 51);
  91. }
  92. }
  93. }
  94. > footer {
  95. margin: 0 auto 30px;
  96. padding: 0 10px;
  97. width: 80px;
  98. > div {
  99. margin: 0 auto;
  100. width: 40px;
  101. height: 40px;
  102. border-radius: 20px;
  103. display: flex;
  104. align-items: center;
  105. justify-content: center;
  106. color: #fff;
  107. }
  108. > p {
  109. margin-top: 5px;
  110. width: 100%;
  111. text-align: center;
  112. word-wrap: break-word;
  113. white-space: nowrap;
  114. text-overflow: ellipsis;
  115. overflow: hidden;
  116. }
  117. }
  118. }
  119. </style>