Home Web Front-end uni-app How to pass the uniapp image address to VIEW

How to pass the uniapp image address to VIEW

Apr 18, 2023 pm 03:20 PM

In the process of developing applications using Uniapp, we often need to display images on the page. Many times, we need to obtain the image address through the interface and then display it on the page. So, how to pass the image address to VIEW? This article will introduce it to you in detail.

1. Use the img tag

In Uniapp, you can use the HTML img tag to display images. You can use the following code in the template:

<img :src="imageUrl" />
Copy after login

where imageUrl is the address of the image. In Vue, you can pass data by binding a variable.


<script>
export default {
  data() {
    return {
      imageUrl: "http://www.image.com/img.jpg"
    }
  }
}
</script>
Copy after login

By binding imageUrl in data, it can be passed easily.

2. Use background images

In addition to using the img tag, you can also use CSS background-image to set a background image. The advantage of this method is that you can set the position, size and other styles of the picture, giving you greater freedom. Use the following code in the template:

<div :style="{ backgroundImage: &#39;url(&#39; + imageUrl + &#39;)&#39; }"></div>
Copy after login

where imageUrl is also the address of the image. Binding can also be passed through data in Vue.


<script>
export default {
  data() {
    return {
      imageUrl: "http://www.image.com/img.jpg"
    }
  }
}
</script>
Copy after login

3. Use the uni-image component

In addition, Uniapp also provides the uni-image component for displaying pictures. Using the uni-image component, you can also set the placeholder image for image loading and error. Use the following code in the template:

<uni-image :src="imageUrl" :loading-src="loadingImage" :error-src="errorImage"></uni-image>
Copy after login

where imageUrl is also the address of the image. loadingImage and errorImage are placeholder images during loading and error respectively. Binding can also be passed through data in Vue.


<script>
export default {
  data() {
    return {
      imageUrl: "http://www.image.com/img.jpg",
      loadingImage: "http://www.image.com/loading.png",
      errorImage: "http://www.image.com/error.png"
    }
  }
}
</script>
Copy after login

The above is how to pass the image address to VIEW in uniapp. You can choose according to the actual situation. If you just want to simply display the image, you can use the img tag or background image; if you need to set the placeholder image during loading and error, you can use the uni-image component.

The above is the detailed content of How to pass the uniapp image address to VIEW. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1659
14
PHP Tutorial
1259
29
C# Tutorial
1233
24