vue单文件 style important引入样式

使用@import引入外部css,作用域是全局的

<template>

</template>

<script>
    export default {
        name: "user"
    };
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
@import "../static/css/user.css";
.user-content{
  background-color: #3982e5;
}
</style>

import并不是引入代码到<style></style>里面,而是发起新的请求获得样式资源,并且没有加scoped

<style scoped>
@import "../static/css/user.css";
</style>

我们只需把@import改成<style src=""></style>引入外部样式,就可以解决样式是全局的问题

<style scoped src="../static/css/user.css">
<style scoped>
.user-content{
  background-color: #3982e5;
}
</style>
原文地址:https://www.cnblogs.com/mengfangui/p/9377415.html