Home > Web Front-end > JS Tutorial > body text

Set background image in Vue

亚连
Release: 2018-06-05 16:55:54
Original
4457 people have browsed it

Below I will share with you a method of setting background images in Vue projects. It has good reference value and I hope it will be helpful to everyone.

In the development of Vue projects, we often add background images to the page. However, after we add the background image to the style, compile and package it, and configure it on the server, due to path resolution problems, the image It cannot be displayed correctly, as shown in the following CSS style:

background:url("../../assets/head.jpg");
Copy after login

At this time we have to consider using other methods. Node provides a more effective way to solve this problem:

1. Define it in data as follows:

 export default {
 name: 'productdetailspage',
 data() {
  return {
   note: {
   backgroundImage: "url(" + require("../../assets/save.png") + ")",
   backgroundRepeat: "no-repeat",
   backgroundSize: "25px auto",
   marginTop: "5px",
   },
  }
 },
Copy after login

2. Introduce the style through inline style

<p class="note" :style ="note"></p>
Copy after login

This can perfectly solve this problem.

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Demonstrate by implementing http request and loading in Vue2.0

How to learn the process and child_process modules in node (Detailed tutorial)

Method of cross-domain request through jQuery JSONP (Detailed tutorial)

The above is the detailed content of Set background image in Vue. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
vue
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!