1.安装相关模块:
npm install node-sass --save-dev
npm install sass-loader --save-dev
2.打开webpack.base.config.js在loaders里面加上:
rules: [ { test: /.vue$/, loader: 'vue-loader', options: vueLoaderConfig }, { test: /.js$/, loader: 'babel-loader', include: [resolve('src'), resolve('test')] }, { test: /.(png|jpe?g|gif|svg)(?.*)?$/, loader: 'url-loader', query: { limit: 10000, name: utils.assetsPath('img/[name].[hash:7].[ext]') } }, { test: /.scss$/, loaders: ["style", "css", "sass"] }, { test: /.(woff2?|eot|ttf|otf)(?.*)?$/, loader: 'url-loader', query: { limit: 10000, name: utils.assetsPath('fonts/[name].[hash:7].[ext]') } } ] }
3.在.vue文件中使用
<style lang='scss' scoped> // 填加自己的内容 </style>