Display image img in Vue

Preface

Dao friends who are new to Vue, I believe that even a simple one will cause everyone a headache. Therefore, there are two common ways to import pictures in Vue.

Use import method

Code in "template"

<img :src="defaultImg" />

Code in "script":

import deImg  from '@/assets/images/defaultImg.jpg'
export default {
    
    
		data () {
    
    
				return {
    
    
				 	defaultImg:deImg  
				  }
		 }
}

Use require method

Code in "template"

<img :src="defaultImg" />

Code in "script":

export default {
    
    
		data () {
    
    
				return {
    
    
				 	defaultImg:require('@/assets/images/defaultImg.jpg')
				  }
		 }
}

Echo the picture returned by the server

Dynamically stitch the image address in the src of img: Insert picture description here
$host is a global variable (defined in main.js)
Insert picture description here

The effect is as follows:
Insert picture description here

Guess you like

Origin blog.csdn.net/u010312671/article/details/106552035