html - Vue.js v-bind:style 伪元素 :: 在内容图标之后
问题描述
我有一个 Bootstrap Vue ProgressBar。我需要在带有内容图标(来自FontAwsome)之后添加到类“.progress-bar”伪元素::。我也希望它是动态的。因为我已经在我的 ProgressBar 中实现了步骤(从 0 tp 100)并且我想要,当我点击时,这个图标将与 ProgressBar 线一起出现。
<b-progress v-bind:style="styleProgressBar" :value="counter" :max="max"></b-progress>
export default {
components:{
'navbar':navbar
},
name: "myPage",
data() {
return {
counter: 0,
max: 100,
step:1,
}
},
methods:{
prev() {
this.step--;
},
next() {
this.step++;
if (this.counter < 100) {
this.counter += 34;
}
}
}
}
我也看到了这个:https ://vuejs.org/v2/guide/class-and-style.html
<div v-bind:style="styleObject"></div>
data: {
styleObject: {
color: 'red',
fontSize: '13px'
}
}
解决方案
假设您有一个父组件:
<div id="parent">
<ChildComponent id="child"> // Possibly from another library?
</div>
// renders ->
<div id="parent">
<div id="child">
<div id="child-component-item">
::after
</div>
</div>
</div>
挑战在于为选择器创建绑定#child-component-item:after
。
我们可以使用 css vars 来解决这个问题,通过一些 CSS 来“进入”子组件。请注意,::v-deep
如果您的风格是scoped
.
父组件.js
<div id="parent-component" :style="{'--bgColor': bgColor}">
<ChildComponent>
</div>
<script>
export default {
data() {
return {
bgColor: 'red'
}
}
}
</script>
<style>
#child-component-item:after {
background-color: var(--bgColor)
}
</style>
推荐阅读
- sql - 为每个(汽车、型号)选择最高“租赁价格”
- ios - 无法从阵列中获取要播放的正确音频文件
- javascript - Javascript对象解构/操作
- web-services - 将 Spring Webflow 应用程序公开为 Web 服务
- r - 如何使用列标题中的希腊字母在 rmarkdown 中创建表格?
- r - 如何将数据从长格式重塑为宽格式以实现此输出?
- java - AWS Java SDK SQSlistener 端点问题
- c++ - 为什么将 std::lock 放在 std::lock_guard 之前
- ruby - 如何在 ruby 中根据 UUID 生成 UTID?
- sql-server - 使用多行从 vb.net 更新存储过程