vue.js - Gridsome / Vue 上的 Tailwind 配置背景图像路径
问题描述
我在我们的 Gridsome 创建的网页中使用 Tailwind,但在 tailwind.config.js 文件中的 backgroundImage 中出现错误。这是文件:
module.exports = {
purge: [],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {
backgroundImage: theme => ({
'mobile': "url('~/assets/mobile_background.jpg')"
})
},
},
variants: {
extend: {},
},
plugins: [],
}
我得到的错误是:
未找到此相关模块:
- ../../../../../../../assets/mobile_background.jpg 在 ./node_modules/css-loader/dist/cjs.js??ref--2-oneOf-1 -1!./node_modules/postcss-loader/src??ref--2-oneOf-1-2!./src/main.css
解决方案
经过一番尝试,我找到了解决方案。我必须将 assets 文件夹放在 /static 下才能在 tailwind.config.js 中使用它,如下所示:
extend: {
backgroundImage: theme => ({
'mobile': "url('~/assets/mobile_background.jpg')"
})
},
推荐阅读
- c++ - 向现有 MFC 类添加自动化方法
- python - 使用正则表达式标记化的 NLP 词干和词形还原
- php - PHP用逗号和空格验证数字
- flutter - 在 Flutter 中创建垂直按钮菜单的最佳方法是什么?
- javascript - 反应:无法使用 useContext 钩子在 app.js 中设置上下文状态
- reactjs - 如何正确显示日期?
- c# - 计算的只读成员作为计算列
- python - django URLs MultipleObjectsReturned 错误
- angular - 在 Angular 8 中创建热键
- android - 如何从 DaggerApplication 中的 UncaughtExceptionHandler 启动活动