以前vue-cli3引入postcss的配置: http://www.javashuo.com/article/p-rzjrodnb-es.htmljavascript
发现这么一个问题,我再全局global.css中定义变量css
:root { --primary-color: red; }
在其余文件中使用div{color: var(--primary-color)}时,会报错variable '--primary-color' is undefined and used without a fallbackhtml
解决办法: http://www.javashuo.com/article/p-rzjrodnb-es.html中第二步去掉,改成:vue
2. 在项目根目录下建立postcss.config.js,内容为:java
module.exports = { "plugins": { "postcss-import": {}, "postcss-cssnext": {} } }
注意:在使用global.css中定义的css变量时,要@import "目录/Global.css"引入(即便main.ts中已经引入过), 否则仍是会报上面的错误vue-cli