<a-spin>包裹元素,使得元素height:100%属性失效

这几天做vue界面,遇到了很奇怪的bug,元素height:100%时此元素直接消失。
通过设置border可以检查得出是 a-spin 包裹且此spin不继承父元素的高度反而是继承子元素的高度。
如果子元素有固定高度时 a-spin 会撑开,但是如果子元素设置为100%。 a-spin 的height会变成0,同时子元素也挤压消失。
解决方法有穿透写style

<style scoped>
  :deep(.ant-spin-nested-loading) {
    width: 100%;
    height: 100%;
    display: block !important;
  }
  :deep(.ant-spin-container) {
    width: 100%;
    height: 80%;
    display: block !important;
  }
</style>

添加此代码使得 a-spin 的height chain连贯就不会压缩子元素了。

posted @ 2025-12-05 15:15  Wadeyi  阅读(1)  评论(0)    收藏  举报