dak*_*ako 1 html css sass webpack vuejs2
我有一个非常奇怪的问题。在使用 Vue CLI 新鲜生成的 vue.js 项目中,我的 scss 文件无法正常工作。我正在使用 vue.config.js 中配置的 scss,如下所示:
module.exports = {
css: {
loaderOptions: {
sass: {
prependData: `
@import "@/scss/all.scss";
`
}
}
}
};
Run Code Online (Sandbox Code Playgroud)
我的 scss 文件夹中有多个文件,直到我在单个文件组件中使用作用域关键字(例如我的 nav.txt)之前,这些文件都没有问题。然后由于某种原因我的全局样式被忽略:
<template>
<div class="nav">
<ul class="nav__menu">
<li class="nav__item">
<span>item</span>
</li>
<li class="nav__item">
<span>item</span>
</li>
<li class="nav__item">
<span>item</span>
</li>
<li class="nav__item">
<span>item</span>
</li>
</ul>
</div>
</template>
<script>
export default {};
</script>
<style lang="scss" scoped>
.nav {
/* Permalink - use to edit and share this gradient: https://colorzilla.com/gradient-editor/#1e5799+0,00c2a9+100 */
background: rgb(30, 87, 153); /* Old browsers */
background: -moz-linear-gradient(
top,
rgba(30, 87, 153, 1) 0%,
rgba(0, 194, 169, 1) 100%
); /* FF3.6-15 */
background: -webkit-linear-gradient(
top,
rgba(30, 87, 153, 1) 0%,
rgba(0, 194, 169, 1) 100%
); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(
to bottom,
rgba(30, 87, 153, 1) 0%,
rgba(0, 194, 169, 1) 100%
); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#00c2a9',GradientType=0 ); /* IE6-9 */
border-radius: 15px;
color: #fff;
height: calc(100vh - 8px);
padding: 10px;
position: fixed;
top: 4px;
left: 4px;
width: 200px;
z-index: 5;
}
</style>
Run Code Online (Sandbox Code Playgroud)
全局样式:
// not working
html {
background: black;
box-sizing: border-box;
font-size: 13px;
// but this is working
*,
*::before,
*::after {
box-sizing: inherit;
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,这种情况从未发生在我身上。有什么东西我错过了,因为我看不到它:( 提前致谢。
我使用的是 Manjaro Linux 18.1.5、node.js 10.16.0 和 npm 6.13.1(如果有帮助的话)。
对于未来的读者 - 我发现了问题...如果组件不包含非空样式标签,则不会将 scss 文件导入到组件中。
发现在所有组件中导入每个 scss 文件几乎是一个坏主意,因为它最终会导致一个非常大的 css 文件,并包含大量未使用/重复的代码。
所以现在我只使用“全局”scss 文件作为变量和混合,一切都运行顺利。
归档时间: |
|
查看次数: |
2733 次 |
最近记录: |