mx-search.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <uv-search v-bind="{...props, ...attrs}">
  3. <template v-for="name in Object.keys($slots)" #[name]>
  4. <slot :name="name"/>
  5. </template>
  6. <template v-if="!$slots.suffix" #suffix>
  7. <uv-button type="primary" shape="circle" size="mini" :text="actionText" @click="handleSearch"/>
  8. </template>
  9. </uv-search>
  10. </template>
  11. <script setup>
  12. import {useAttrs} from 'vue';
  13. import {createPropDefine} from "@/utils";
  14. import {func} from "@/uni_modules/uv-ui-tools/libs/function/test";
  15. import {searchProps} from "@/uni_modules/uv-search/components/uv-search/uv-search.vue";
  16. // 事件会自然穿透,因为默认inheritAttrs=true
  17. // 因为外部事件会被分别为attrs,但如果这里也申明事件,则attrs中就会接收不到
  18. const props = defineProps({
  19. ...searchProps,
  20. showAction: createPropDefine(false, Boolean)
  21. })
  22. const attrs = useAttrs()
  23. const handleSearch = () => {
  24. // 因为这里用了事件穿透的方式,这里就不要emit外抛了,直接调用attrs中的方法就可以了
  25. if (func(attrs.onSearch)) attrs.onSearch()
  26. }
  27. </script>
  28. <style scoped lang="scss">
  29. ::v-deep(.uv-search) {
  30. .uv-search__content {
  31. padding-right: 3px;
  32. .uv-button--mini {
  33. height: 28px;
  34. }
  35. .uv-button__text {
  36. font-size: 12px !important;
  37. }
  38. }
  39. }
  40. </style>