q***@163.com
q***@163.com
  • 发布:2023-08-15 11:30
  • 更新:2024-01-27 15:11
  • 阅读:172

【报Bug】 编译运行到浏览器后,插入到<style></style>中的css代码的作用域和dom中实际运行标签的作用域不一致,导致样式无法命中。

分类:HBuilderX

产品分类: HbuilderX

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: 11.6

HBuilderX版本号: 3.8.7

操作步骤:

以下为vue中template的部分代码,其中refresh-list为自定义组件。

<refresh-list id="refresh-list-comp" @getListData="getListData($event, { tagId: 'refresh-list-comp' })">  
  <view class="refresh-list-inner" slot="innerList">  
    <view class="func-amount-header">  
      <image class="image" mode="aspectFill" src="/static/packageSearch/images/pic_zhifuedu@2x.png" />  
    </view>  
    <view class="card-list">  
      <view class="card-wrap" v-for="(item, index) in recordList" :key="index">  
        <view class="card-header"></view>  
        <view class="card-body"></view>  
      </view>  
    </view>  
  </view>  
  <view slot="imageEmpty"><image src="/static/images/pic_zanwu@3x.png" mode="widthFix" style="width: 100%"></image></view>  
</refresh-list>

以下是部分对应的原始css:

.container #refresh-list-comp .refresh-list-inner {  
  width: 702rpx;  
  margin: 0 auto;  
}  
.container #refresh-list-comp .refresh-list-inner .func-amount-header {  
  width: 702rpx;  
  height: 118rpx;  
}  
.container #refresh-list-comp .refresh-list-inner .func-amount-header .image {  
  width: 100%;  
  height: 100%;  
}  
.container #refresh-list-comp .refresh-list-inner .card-list {  
  background-color: #fff;  
  overflow: hidden;  
}

预期结果:

希望样式可以正常命中。

实际结果:

编译并运行到浏览器中后,查看<style></style>中的样式,发现加上了作用域[data-v-1fe11125] :

.container #refresh-list-comp .refresh-list-inner[data-v-1fe11125] {  
  width: 365px;  
  margin: 0 auto;  
}  
.container #refresh-list-comp .refresh-list-inner .func-amount-header[data-v-1fe11125] {  
  width: 365px;  
  height: 61px;  
}  
.container #refresh-list-comp .refresh-list-inner .func-amount-header .image[data-v-1fe11125] {  
  width: 100%;  
  height: 100%;  
}  
.container #refresh-list-comp .refresh-list-inner .card-list[data-v-1fe11125] {  
  background-color: #fff;  
  overflow: hidden;  
}

但是dom中.refresh-list-inner和.func-amount-header上的作用域都是[data-v-0dc14f84],详见附件。导致css样式没有命中。

bug描述:

编译运行到浏览器后,插入到<style></style>代码中的css代码的作用域和dom中实际运行标签的作用域不一致,导致样式无法命中。

2023-08-15 11:30 负责人:DCloud_UNI_HRK 分享
已邀请:
q***@163.com

q***@163.com (作者)

没人回复吗?

q***@163.com

q***@163.com (作者)

官方没人看这个问题吗

q***@163.com

q***@163.com (作者)

我发现可能是因为我引用的scss文件。

<style lang="scss">  
@import './refresh-list.scss';  
</style>

如果是上面的代码,就会出现问题。如果我改成下面这样,就没问题。

<style lang="scss">  
@import './refresh-list.css';  
</style>

真是奇怪,始终是<style lang="scss">,但是改变一下引用文件的类型就会不一样。希望官方看看这个问题。

  • DCloud_UNI_HRK

    方便提供一下简单的问题工程吗?(zip压缩包,包含scss文件)

    2024-01-27 15:36

要回复问题请先登录注册