demo1.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <div class="m-color__section">
  3. <div class="m-color__top" :style="{backgroundColor: state.currentColor}">
  4. <p class="m-color__title">Brand Color</p>
  5. <p class="m-color__desc">{{state.currentColor}}</p>
  6. </div>
  7. <div class="m-color__bottom">
  8. <div @click="mColorItemAction(index)" :style="{backgroundColor: item}" v-for="(item, index) in state.colorList" :key="index" class="m-color__item"></div>
  9. </div>
  10. </div>
  11. </template>
  12. <script setup>
  13. import { reactive } from 'vue-demi';
  14. const state = reactive({
  15. currentColor: '#409EFF',
  16. colorList: ['#409EFF', '#337ECC', '#79BBFF', '#A0CFFF', '#C6E2FF', '#D9ECFF', '#ECF5FF']
  17. })
  18. const mColorItemAction = (index) => {
  19. state.currentColor = state.colorList[index];
  20. }
  21. </script>
  22. <style lang="scss" scoped>
  23. // @import '../../styles/components/button.scss';
  24. .m-color__section {
  25. width: 326px;
  26. height: 112px;
  27. border-radius: 5px;
  28. .m-color__top {
  29. color: #fff;
  30. height: 60%;
  31. padding: 10px 0 0 20px;
  32. border-top-left-radius: 5px;
  33. border-top-right-radius: 5px;
  34. .m-color__title {
  35. font-size: 16px;
  36. }
  37. .m-color__desc {
  38. font-size: 14px;
  39. }
  40. }
  41. .m-color__bottom {
  42. height: 40%;
  43. display: flex;
  44. .m-color__item {
  45. width: calc(100% / 7);
  46. cursor: pointer;
  47. }
  48. }
  49. }
  50. </style>