This time I will bring you a detailed explanation of the use of Vue bass.scss, and what are the precautions for using Vue bass.scss. The following is a practical case, let’s take a look.
In order to solve the problem of globally introducing scss variables and mixins in Vue components, a parser named "sass-resources-loader" is loaded.
Installation
$ > cnpm i -D sass-resources-loader
Configuration
If configured, it is configured in the loader parser of vue, that is, in vue-cli The file built by the scaffolding method is build/utils.js. The cssLoaders() method is defined in this file. This method defines the parsing methods of css and less, as follows.
// build/utils.js exports.cssLoaders = function (options) { options = options || {} ... return { // ... sass: generateLoaders('sass', { indentedSyntax: true }), // 定义在这里 =======================》 scss: generateLoaders('sass').concat( { loader: 'sass-resources-loader', options: { resources: path.resolve(__dirname, '../src/common/style/global.scss') // 需要全局引入的文件 } } ), // 定义在这里 =======================》 // ... } } // global.scss @mixin line-height($height) { height: $height; line-height: $height; } $head-height: .45rem; // xx.vue <style lang="scss"> height: @include line-height(45px); </style>
Recommendation
Only variables or mixins need to be defined in global.scss.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How to use the better-scroll plug-in in the project
A detailed explanation of the mutual communication function of controllers in Angularjs
The above is the detailed content of Detailed explanation of Vue+bass.scss usage. For more information, please follow other related articles on the PHP Chinese website!