打赏

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>

 

posted @ 2018-07-27 14:33  孟繁贵  阅读(14238)  评论(0编辑  收藏  举报
TOP