【问题标题】:vue-cli: Error when trying to load an image from assets foldervue-cli:尝试从资产文件夹加载图像时出错
【发布时间】:2018-11-26 09:56:50
【问题描述】:

我正在使用 vue-cli 3,我有这种风格:

.login-page {
  ...
  background: url("~@/assets/login-bg.jpg") no-repeat;
  background-size: cover;
  background-position: center;
  ...
}

当我运行yarn serve 时出现此错误:

./src/assets/login-bg.jpg 模块构建失败(来自 ./node_modules/url-loader/index.js):类型错误 [ERR_INVALID_ARG_TYPE]: “id”参数必须是字符串类型。接收到的类型对象 在 Module.require (internal/modules/cjs/loader.js:630:11) 在需要(内部/模块/cjs/helpers.js:20:18) 在 Object.module.exports (C:\aquaprojects\src\bitbucket.org\salock\server\tmui\node_modules\url-loader\index.js:35:24)

我在加载 SVG 时没有问题,我缺少什么?

【问题讨论】:

  • 你的background: url("...中不应该是~或@
  • 在 JS 中是 @,在样式中是 ~@

标签: vue.js webpack vue-cli


【解决方案1】:

不知道为什么,但我删除了我的 node_modules 并重新安装,它可以工作

【讨论】:

  • 有时你需要重新启动你的窗口,所以想再次工作;-)
猜你喜欢
  • 1970-01-01
  • 2023-04-03
  • 2019-07-24
  • 2019-09-13
  • 2019-01-03
  • 1970-01-01
  • 2020-08-13
  • 2013-08-04
  • 2017-08-31
相关资源
最近更新 更多