```where, imageUrl"/> ```where, imageUrl">
Home >Web Front-end >uni-app >How to pass the uniapp image address to VIEW
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" />
where imageUrl is the address of the image. In Vue, you can pass data by binding a variable.
<img :src="imageUrl" /><script> export default { data() { return { imageUrl: "http://www.image.com/img.jpg" } } } </script>
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: 'url(' + imageUrl + ')' }"></div>
where imageUrl is also the address of the image. Binding can also be passed through data in Vue.
<div :style="{ backgroundImage: 'url(' + imageUrl + ')' }"></div> <script> export default { data() { return { imageUrl: "http://www.image.com/img.jpg" } } } </script>
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>
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.
<uni-image :src="imageUrl" :loading-src="loadingImage" :error-src="errorImage"></uni-image> <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>
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!