Vue's dig pits and crawl pits CSS background graphic style Ultimate solution

Source: Internet
Author: User

Original Problem
#wrapper {        width:100%;         height:100%;         position:fixed;         background-image:url (./img/open_bg.jpg)    }

In the CSS style in the. vue file, use the background map

After Webpack packing, the path is wrong, how to do?

Reply

If you use Vue-cil, then in the build directory to find the utils.js in the Extracttextplugin.extract ({}), add the following this attribute is the perfect solution to Publicpath: '. /.. /‘

Explain

The file will eventually be packaged and compressed to JS. When running, the relative path in the CSS points to the root directory that has changed, so there is an issue with the loading error.

Here is an explanation of this plugin.

Extract-text-webpack-plugin

Role: The main purpose of this plugin is to pull away from CSS style, to prevent the style of packaging in JS caused by the page style loading confusion phenomenon.

Plug-in Parameters: the plug-in has three parameters of the following meanings:

Use: Refers to what kind of loader to compile the file, here because the source file is. css so choose Css-loader
Fallback: What loader to use to extract CSS files after compilation
Publicfile: The file path that is used to overwrite the project path and generate the CSS file

Source

https://www.zhihu.com/question/39953434

Vue's dig pits and crawl pits CSS background graphic style Ultimate solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.