]."/> ].">

Home  >  Article  >  Web Front-end  >  How to change the background image in vue.js

How to change the background image in vue.js

coldplay.xixi
coldplay.xixiOriginal
2020-11-11 14:42:454305browse

How to change the background image in vue.js: introduce the style through inline style, use the [require()] method, the code is [1ae34f455fdc17e8cfabcbae5fd5634916b28748ea4df4d9c2150843fecfba68] .

How to change the background image in vue.js

The operating environment of this tutorial: windows10 system, vue2.9, this article is applicable to all brands of computers.

【Recommended related articles: vue.js

How to change the background image in vue.js:

In Vue project development, we often add background images to the page. However, when we add the background image to the style, compile and package it, and configure it on the server, the image is not correct due to path resolution problems. It is displayed with the following CSS style:

background:url("../../assets/left-bg.jpg");

At this time we will You should consider using other methods. Node provides a more effective way to solve this problem. The method is as follows:

is defined in data as follows:

  data() {
    return {
      leftBg: {
        background: "#235d8b url(" + require("./assets/left-bg.png") + ") no-repeat scroll 0 bottom",
      },
      topBg: {
        background: "#235d8b url(" + require("./assets/top-bg.png") + ") no-repeat scroll right 0",
        height: '80px'
      }
    }
  }

use require() Method, require() is a node.js method.

Introduce styles through inline styles:

1ae34f455fdc17e8cfabcbae5fd5634916b28748ea4df4d9c2150843fecfba68

##Related free learning recommendations: JavaScript(Video)

The above is the detailed content of How to change the background image in vue.js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn