官方示例:https://github.com/nuxt/nuxt....
在nuxt.js中assets下面定义了mixins.scss,想在项目中全局引用,其中有一个变量 $theme_color我在test.vue中使用import引入scss文件,调用变量正常
test.vue
<style lang="scss" scoped>
@import '~assets/sass/mixins.scss';
.bottom-tab-bar {
.tab-item {
color: $theme_color;
}
}
</style>
但是这样比较繁琐,每个页面都得import,所以看了解决方案说在nuxt.config.js里面引入
nuxt.config.js
module.exports = {
...
build: {
// You cannot use ~/ or @/ here since it's a Webpack plugin
styleResources: {
scss: './assets/sass/init.scss'
}
}
...
}
报错提示这个
File to import not found or unreadable: ....
这个问题怎么解决呢?
原来搭配了一个
@nuxtjs/style-resources
模块,nuxt.config.js
里配置是这样的 :但是会导致重复加载样式, 有多少个子组件就重复加载多少次, 后来改为 :
一样能用, 也不重复加载了