validity.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div>
  3. <div
  4. class="spec-card"
  5. :class="{ active: active == item.name }"
  6. @click="clickCard(item)"
  7. v-for="(item, index) in list"
  8. :key="index"
  9. >
  10. {{ item.name }}
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. name: 'validity',
  17. components: {},
  18. props: {
  19. deactive: {
  20. // 默认选中的 name
  21. type: String,
  22. default: '2年'
  23. },
  24. list: {
  25. // 传入数据
  26. type: Array,
  27. default() {
  28. return []
  29. }
  30. }
  31. },
  32. data() {
  33. return {
  34. active: ''
  35. }
  36. },
  37. created() {
  38. this.active = this.deactive
  39. },
  40. mounted() {},
  41. beforeDestroy() {},
  42. filters: {},
  43. computed: {},
  44. watch: {},
  45. methods: {
  46. clickCard(item) {
  47. this.active = item.name
  48. // 回传当前选中数据
  49. this.$emit('onclick', item)
  50. }
  51. }
  52. }
  53. </script>
  54. <style lang="scss" scoped>
  55. .spec-card {
  56. position: relative;
  57. display: flex;
  58. // flex-direction: column;
  59. align-items: center;
  60. justify-content: center;
  61. // padding: 16px;
  62. margin-right: 16px;
  63. width: 140px;
  64. height: 40px;
  65. background-color: #f5f6f7;
  66. border-radius: 4px;
  67. border: 1px solid transparent;
  68. box-sizing: border-box;
  69. cursor: pointer;
  70. &.active {
  71. border-color: #2abed1;
  72. background-color: #fff;
  73. &::after {
  74. content: '';
  75. position: absolute;
  76. right: -1px;
  77. bottom: -1px;
  78. width: 19px;
  79. height: 19px;
  80. background-image: url(~@/assets/images/spec-active.png);
  81. background-repeat: no-repeat;
  82. background-size: contain;
  83. }
  84. }
  85. }
  86. </style>