1

I want to create a custom image component in NuxtJS (to pass rgb color and it automatically colorize the image), but I dont get it working that it loads my image when the img in my CustomImage Component get the path passed.

Error:

logotext.png:1 GET http://localhost:8080/@/assets/images/logotext.png 404 (Not 
Found)

My CustomImage:

<template>
  <img  :src="src" :alt="alt" />
</template>

<script lang="ts">
import Vue from 'vue';
import { Component, Prop } from 'nuxt-property-decorator';

@Component({})
export default class CustomImage extends Vue {
  @Prop({
    type: String,
    required: true,
  })
  public src!: string;
  @Prop({
    type: String,
    required: true,
  })
  public alt!: string;
}
</script>
5
  • how are you defining and passing the src url? Commented Jun 21, 2020 at 10:14
  • <CustomImage src="@/assets/images/logotext.png" alt="Logo" /> Commented Jun 21, 2020 at 10:15
  • 1
    Try <CustomImage src="~/assets/images/logotext.png" alt="Logo" /> if that doesn't work, move the images to images folder in static directory and use it like <CustomImage src="/images/logotext.png" alt="Logo" /> Commented Jun 21, 2020 at 10:20
  • Thank you. The solution with the static folder worked for me! Commented Jun 21, 2020 at 10:23
  • 1
    Ok i will posy it as answer Commented Jun 21, 2020 at 10:24

1 Answer 1

1

Create a folder called images inside the static directory and move your images into it, then use them as follows :

 <CustomImage src="/images/logotext.png" alt="Logo" />

the / refers to static directory.

check this for more details

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.