@hlw-uni/mp-vue 1.1.15 → 1.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hlw-uni/mp-vue",
3
- "version": "1.1.15",
3
+ "version": "1.1.16",
4
4
  "description": "hlw-uni Vue 组件库 — 供小程序业务方使用的 UI 组件集合",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -23,7 +23,7 @@
23
23
  <view v-if="props.icon" :class="props.icon" class="hlw-btn-icon" />
24
24
  </slot>
25
25
  </view>
26
- <view class="hlw-btn-content">
26
+ <view v-if="hasContent" class="hlw-btn-content">
27
27
  <slot />
28
28
  </view>
29
29
  </template>
@@ -31,7 +31,7 @@
31
31
  </template>
32
32
 
33
33
  <script setup lang="ts">
34
- import { computed, useSlots } from "vue";
34
+ import { computed, useSlots, Comment } from "vue";
35
35
 
36
36
  type ButtonType =
37
37
  | "primary"
@@ -85,6 +85,17 @@ const emit = defineEmits<{ click: [] }>();
85
85
  const slots = useSlots();
86
86
  const hasIcon = computed(() => Boolean(props.icon || slots.icon));
87
87
 
88
+ /** 默认 slot 是否有非注释节点内容,用于避免空 slot 占位影响 flex 布局 */
89
+ const hasContent = computed(() => {
90
+ const nodes = slots.default?.();
91
+ if (!nodes || nodes.length === 0) return false;
92
+ return nodes.some((n) => {
93
+ if (n.type === Comment) return false;
94
+ if (typeof n.children === "string") return n.children.trim() !== "";
95
+ return true;
96
+ });
97
+ });
98
+
88
99
  const buttonStyle = computed(() => {
89
100
  const style: Record<string, string> = {};
90
101