是否可以将CSS注入Vue组件样式部分?

时间:2018-07-17 21:35:25

标签: css vue.js vue-component

我想做的事的例子

  <template>
      <div>
        <p>I pee red!</p>
      </div>
    </template>
    <script>

    export default {
      data: () => ({
        aModelWithStyle: {name: "Hansel", css:".p{color:red}"}
      })  
    }
    </script>

    <style scoped lang="scss">
      {{aModelWithStyle.css}}
    </style>

显然,样式标签中的{{aModelWithStyle.css}}不起作用。我将如何使用Vue完成此操作?

2 个答案:

答案 0 :(得分:0)

“您无法在运行时通过组件的JavaScript动态更改样式-否。”

https://forum.vuejs.org/t/is-it-possible-to-inject-css-into-vue-component-style-section/38813/3?u=three60

答案 1 :(得分:-2)

vue文档说您可以使用

<style src="./my-component.css"></style>

我不确定这是否正是您要的内容,但这是我的最佳猜测。

相关问题