Skip to content
On this page

v-bind 的小技巧

Authors

vue.js 中,我们可以像在 <template> 块中一样在 <style> 块中使用响应式值:

vue
<style scoped>
.btn{
  color: v-bind(buttonColors);
}
</style>

在幕后,Vue 使用针对每个组件的 CSS 计算属性(也称为 CSS 变量)。

CSS 保持静态不变,但是我们可以在响应式值更改时动态更新 CSS 变量。

有关更多信息,请参阅文档:https://cn.vuejs.org/api/sfc-css-features.html#v-bind-in-css

has loaded