我想从src文件夹设置我的照片地址,并且基于vue doc我必须使用@。问题是,当我使用它时,jetbrains用红线在地址下划线,并且我的页面也不再编译,错误是:
Failed to compile.
./node_modules/css-loader?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-7ba5bd90","scoped":false,"hasInlineConfig":false}!./node_modules/sass-loader/lib/loader.js?{"indentedSyntax":true,"sourceMap":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!./src/App.vue Module not found: Error: Can't resolve './@/assets/image/background.png' in '/home/sina/WebstormProjects/landing-vue/src' @ ./node_modules/css-loader?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-7ba5bd90","scoped":false,"hasInlineConfig":false}!./node_modules/sass-loader/lib/loader.js?{"indentedSyntax":true,"sourceMap":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!./src/App.vue 7:749-791 @ ./node_modules/vue-style-loader!./node_modules/css-loader?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-7ba5bd90","scoped":false,"hasInlineConfig":false}!./node_modules/sass-loader/lib/loader.js?{"indentedSyntax":true,"sourceMap":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!./src/App.vue @ ./src/App.vue @ ./src/main.js @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
这也是CSS:
background: url("@/assets/image/background.png");
答案 0 :(得分:4)
尝试:
background: url("~@/assets/image/background.png")
答案 1 :(得分:0)
我在错误消息中看到:Error: Can't resolve './@/assets/image/background.png'
;这意味着网址./@/assets/image/background.png
可能是错误的。
尝试用./@/assets/image/background.png
替换源代码@/assets/image/background.png
答案 2 :(得分:0)
@
本身与vue
无关,而与Webpack无关。这是路径的别名,因此别名可能会丢失,并且由于@
将不是有效的文件夹,因此它也无法在该路径中找到您的文件。