10

I am new to vue.js and saw this video

https://www.youtube.com/watch?v=LsoLfELhG74

Which says you can do

<style scoped>
</style>

to scope the style, but this is if I embed it into the html page. What if I link to a .css file. How could you still scope the css?

Thanks

1
  • You could try using an @import statement. Not sure if that will actually wok but it's worth a try. Commented Jun 19, 2017 at 1:32

2 Answers 2

15

You can add a src attribute to the style tag like this:

<style scoped src="./test.css">
</style>
Sign up to request clarification or add additional context in comments.

5 Comments

how does this work? How can it just update the external css and add that attribute filter to that?
I'm not sure if I understand what you are asking. It doesn't update the external css file. It will make a new css file based on the external one when you build the project.
the link ./test.css is where exactly ? the . refers to node_modules? or where app.js is or where?
@brahimm this will look in the same directory as the component.
I can confirm this approach works with Sass (.scss) files as well. Thanks!
1

first create a scss file like styles/scss/_variables.scss.In that _variables.scss file import your required styles like $bg-color: red;

Next import that scss file in your required .vue file .

<style lang="scss">
 @import "../styles/scss/_variables.scss";
 .msg {
        background-color: $bg-color;
      }
</style>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.