mx-subsection.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <uv-subsection v-bind="{...props, ...override}" :style="{width: width}">
  3. <template v-for="name in Object.keys($slots)" #[name]="scope">
  4. <slot :name="name" v-bind="scope"/>
  5. </template>
  6. </uv-subsection>
  7. </template>
  8. <script setup>
  9. import {useAttrs, ref, watch, computed} from 'vue';
  10. import {createPropDefine} from "@/utils";
  11. import {func} from "@/uni_modules/uv-ui-tools/libs/function/test";
  12. import {subsectionProps} from "@/uni_modules/uv-subsection/components/uv-subsection/uv-subsection.vue";
  13. // 如果不禁止,uv-subsection会自动处理外部onChange,即可能造成两次调用
  14. defineOptions({inheritAttrs: false})
  15. // 将current响应改为modelValue
  16. const copyProps = {...subsectionProps}
  17. delete copyProps.current
  18. const props = defineProps({
  19. ...subsectionProps,
  20. modelValue: createPropDefine(0, Number),
  21. customStyle: createPropDefine('height:36px;border-radius:18px'),
  22. customItemStyle: createPropDefine('border-radius:15px'),
  23. width: createPropDefine('')
  24. })
  25. const emits = defineEmits(['update:modelValue'])
  26. const attrs = useAttrs()
  27. const override = computed(() => ({
  28. current: props.modelValue, // 内部消化了current
  29. onChange: (index) => {
  30. emits('update:modelValue', index)
  31. // 如果外部绑定了@change,原样调用,不去影响它
  32. if (func(attrs.onChange) && index != props.modelValue) attrs.onChange(index)
  33. }
  34. }))
  35. </script>
  36. <style scoped>
  37. </style>