vue3 中 使用 Jsx 或者 Tsx 语法 添加元素 并且样式 使用 scoped 会不生效-样式不生效

本文详细讲述了如何从tsx代码中移除 scoped 样式属性,以解决因范围限制找不到类名的问题。通过实例演示了如何添加新的未受限style,并解释了编译失效的原因。优化后的代码将确保样式正确显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

动态添加渲染 模块 代码 如下

代码片.


<script lang="tsx">	
	_sums = (
		<div class="sum_row">
		    <div class="bottom-line">
		      {sum * 100}%<font style="display: none;">/</font>
		    </div>
		    <div></div>
		</div>
	);
	
</script>

<style lang="less"  scoped>
.sum_row div {
    min-height: 40px;	
    line-height: 40px;
    width: 100%;
  }
  .sum_row .bottom-line {
    position: relative;
  }
  .sum_row .bottom-line:after {
    content: "";
    position: absolute;
    left: -10px;
    right: -10px;
    bottom: 0;
    height: 1px;
    background-color: #ebeef5;
  }
</style>

解决方法

把 style 的 scoped 去除
<style lang="less">
新加一个 不存在 scoped 的 style
<style lang="less">

出现此问题的原因 可能为
当前页 style 添加 scoped 编译时 在当前页的范围内 未能找到 Jsx(Tsx) 中使用的类,
对代码进行了 优化删减
最后导致 编译后 样式 消失

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值