猫妈狗爸伴宠师小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.3 KiB

  1. <template>
  2. <view class="mt32 question__view" :class="[props.mode]">
  3. <view class="size-28 mb20 question">
  4. {{ `${props.index + 1}${props.data.question}` }}
  5. </view>
  6. <view class="size-28 option"
  7. v-for="(option, oIdx) in props.data.options"
  8. :key="`${props.index}-option-${oIdx}`"
  9. :class="[props.modelValue === option.value ? 'is-selected' : '']"
  10. @click="onClick(option.value)"
  11. >
  12. {{ `${String.fromCharCode(65 + oIdx)}${option.label}` }}
  13. </view>
  14. </view>
  15. </template>
  16. <script setup>
  17. const props = defineProps({
  18. index: {
  19. type: Number,
  20. default: null,
  21. },
  22. data: {
  23. type: Object,
  24. default() {
  25. return {}
  26. }
  27. },
  28. modelValue: {
  29. type: String | Number,
  30. default: null,
  31. },
  32. mode: {
  33. type: String,
  34. default: 'select', // select | display
  35. }
  36. })
  37. const emit = defineEmits(['update:modelValue'])
  38. const onClick = (val) => {
  39. emit('update:modelValue', val)
  40. }
  41. </script>
  42. <style lang="scss" scoped>
  43. .question {
  44. color: #000000;
  45. }
  46. .option {
  47. background-color: #F3F3F3;
  48. color: #707070;
  49. line-height: 37rpx;
  50. padding: 23rpx;
  51. border-radius: 28rpx;
  52. & + & {
  53. margin-top: 20rpx;
  54. }
  55. }
  56. .question__view.select {
  57. .option.is-selected {
  58. background-color: rgba($color: #FFBF60, $alpha: 0.22);
  59. color: #FFBF60;
  60. }
  61. }
  62. </style>