search

Home  >  Q&A  >  body text

javascript - The image referenced in vue fails to load when deployed to the server

Directory Structure:

Code:

<img src="./title.png" />

It can be loaded normally when running on the local server,
But it cannot be loaded when placed on the server (tomcat). The project is deployed in the webapp/myproject/ directory,
The image path that should be requested on the server is http:// 1.1.1.1:8080/myproject...
But the actual requested image path is http://1.1.1.1:8080/static/im...
How to write the image path as the current directory in vue Instead of the server root directory

曾经蜡笔没有小新曾经蜡笔没有小新2698 days ago1322

reply all(3)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-07-05 10:28:18

    I have encountered this problem before and it has been compiled into a document. What you need to modify is the webpack configuration and then repackage it

    reply
    0
  • 習慣沉默

    習慣沉默2017-07-05 10:28:18

    I have also encountered this. When it is placed on the server, the image path at this time should be an absolute path. When it is local, press the <img src="./title.png" /> path. When it is placed on the server, it is < ;img src="/myproject/static/img/title.45ae5f4.png" />. Of course the above method is better

    reply
    0
  • 高洛峰

    高洛峰2017-07-05 10:28:18

    If you are using scaffolding, please familiarize yourself with the uses of several JSs in config, especially index.js

    build: {
            env: require('./prod.env'),
            index: path.resolve(__dirname, '../dist/index.html'),
            assetsRoot: path.resolve(__dirname, '../dist'),
            assetsSubDirectory: 'static', // 附件资源引用子目录
            assetsPublicPath: '项目正式地址', // 服务器资源引用根目录
            productionSourceMap: true,
        }

    reply
    0
  • Cancelreply