【发布时间】:2018-04-05 01:06:49
【问题描述】:
我更喜欢重构,所以在与我的 html 相同的文件中包含样式让我感到厌烦。
我不想使用<style> html 标记,这些标记充满了与我在每个组件中的函数和方法交织在一起的 css。
我想继续使用 sass 或 scss 文件。 (我自己的单个文件 + bootstrap 和我在网上找到的其他通用 scss 文件)。
我该怎么做?
我试过了:
import Vue from 'vue'
import App from './App'
import router from './router'
import './assets/scss/App.scss' <- this is the line I added that broke the app.
Vue.config.productionTip = false
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App }
})
在我的 main.js 中
但我收到 404 错误:
更新:
看了这个:What is the difference between linking stylesheets and requiring them in Webpack + VueJs? 好奇我是否应该切换到使用链接?我试过了,但我不知道我应该把它放在哪里。
我应该指定我从这个脚手架开始:https://github.com/vuejs/vue-cli
第二次更新:
我一直在关注以下指南:https://medium.com/@mahesh.ks/using-sass-scss-in-vue-js-2-d472af0facf9
【问题讨论】:
-
“require('./assets/scss/App.scss')”有效吗?
-
@Wouter no :( ...
-
两者对我来说都很好,无法重现:l(我也使用了 vue-cli)
-
查看更新的 OP,如果知道我从哪里开始有帮助,请告诉我。
-
SACC 或 SCSS 文件需要编译器,你将如何在运行时编译它们?