basicWorkBtn.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div class="basicWorkBtn">
  3. <div :class="activeIndex == index ? 'btn-box1' : 'btn-box'" v-for="(item, index) in workBtnLists" :key="index"
  4. @click="WorkBtnClick(index, item)">
  5. <div class="work-btn-text">{{ item.name }}</div>
  6. </div>
  7. </div>
  8. </template>
  9. <script lang="ts" setup>
  10. import { ref, reactive, defineProps, watch } from 'vue'
  11. let props = defineProps({
  12. workBtnList: {
  13. type: Array,
  14. default: () => {
  15. return []
  16. }
  17. }
  18. })
  19. let workBtnLists = ref<any[]>([])
  20. let activeIndex = ref(0) //当前按钮激活索引
  21. //选项切换
  22. function WorkBtnClick(index, item) {
  23. console.log(index, 'index-----')
  24. activeIndex.value = index
  25. }
  26. watch(() => props.workBtnList, (newV, oldV) => {
  27. console.log(newV, '按钮新数据--------')
  28. workBtnLists.value = newV
  29. }, { immediate: true, deep: true })
  30. </script>
  31. <style lang="less" scoped>
  32. @font-face {
  33. font-family: 'douyuFont';
  34. src: url('../../../assets/font/douyuFont.otf');
  35. }
  36. .basicWorkBtn {
  37. position: relative;
  38. width: 100%;
  39. height: 100%;
  40. display: flex;
  41. align-items: flex-start;
  42. .btn-box {
  43. width: 203px;
  44. height: 74px;
  45. margin: 0px 10px;
  46. display: flex;
  47. justify-content: center;
  48. align-items: center;
  49. background: url('../../../assets/images/workPlaceWarn/work-btn.png') no-repeat center;
  50. background-size: 100% 100%;
  51. cursor: pointer;
  52. &:first-child {
  53. margin-left: 0px;
  54. }
  55. &:last-child {
  56. margin-right: 0px;
  57. }
  58. .work-btn-text {
  59. font-family: 'douyuFont';
  60. font-size: 18px;
  61. color: #fff;
  62. }
  63. }
  64. .btn-box1 {
  65. position: relative;
  66. width: 203px;
  67. height: 92px;
  68. margin: 0px 10px;
  69. background: url('../../../assets/images/workPlaceWarn/work-btn-choice.png') no-repeat center;
  70. background-size: 100% 100%;
  71. cursor: pointer;
  72. &:first-child {
  73. margin-left: 0px;
  74. }
  75. &:last-child {
  76. margin-right: 0px;
  77. }
  78. .work-btn-text {
  79. position: absolute;
  80. left: 50%;
  81. top: 26px;
  82. transform: translate(-50%, 0);
  83. font-family: 'douyuFont';
  84. font-size: 18px;
  85. color: #fff;
  86. }
  87. }
  88. }
  89. </style>