VueJS - Function to display image

DaLoco

I'm new to VueJS and having a hard to on this situation.

display.vue

<template>
   <img :src="getLogo(logo)" /> 
</template>

<script>
 export default {
  methods: {
    getLogo(logo){
        return '../assets/'+logo;
    }
  }
}
</script>

I got an 404 error on that code.

But I tried not using the getLogo() function and it displayed.

<template>
   <img src="../assets/logo.svg" /> 
</template>

The image structure is:

src/assets/logo1.svg

webpack.base.conf.js

test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
 limit: 10000,
 name: utils.assetsPath('img/[name].[hash:7].[ext]')
}

Anybody here can help me displaying the image by using the getLogo function? Thank you very much!

highFlyingSmurfs

I reckon when using v-bind:src it should be as follows

<img v-bind:src="'../assets/logo.svg'">
<!-- or shorthand -->
<img :src="'../assets/logo.svg'">

Notice the ' '

While using <img src="../assets/logo.svg" /> you do not need to bind a string, hence that's why it works.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to dynamically display an image in VueJS?

Function to display image

VueJS + Firebase How do I display an image?

VueJS select object from list and display with function

How to save image link in when using 'require' to display image in VueJS?

Display image button using function

How to display mysql blob image in html using Vuejs?

Display multiple files name VueJS error push is not a function

Vuejs and Request: Computed property function doesnt display GET JSON value

onload image, call function to display alert

How to display the image from ajax success function?

Create function to display an image or placeholder image for a single product

How do you display an image from an axios call into a Vuejs img element? I've seen nothing that works

Display images with VueJS and Laravel

Vuejs Display running balance

Display data in Vuejs

Display translation on a component in Vuejs

I am trying to write a function to display the histogram of an image

Building a PHP function to display an image gallery from a multidimensional array

How to display image in message part in wp_mail function?

Flask: display newly generated image on webpage while continuing with function?

How to create a radio button with on and off function to display an image?

How can I get my function to display text over an image?

Passing image to function as a char array in C++ and display with SFML

Vuejs background image not work

Vuejs 2 image slider

Add text to image VueJS

Image in VueJS component is not loading

Vuejs image url link