@import url() 和 @import 'xxx.css'什么区别?

447 阅读1分钟

@import url() 和 @import 'xxx.css'什么区别?

<style lang="scss" scoped>
    @import url('./xxx.scss');
</style>
<style lang="scss" scoped>
    @import './xxx.scss';
</style>

从现象来看, @import url('xxx.scss')这种形式引入的文件中所有的样式会==提升到全局==,哪怕你没有进入过引入文件的页面。且==不会受scoped约束==。 @import 'xxx.scss'这种形式引入的和直接在style中写的没有任何区别,接受scoped约束。

原理还不清楚,建议大家不要使用@import url('xxx.scss')引入样式,有大佬知道为啥吗~~~