I am using VueJS via VUE CLI and have a component called Icon.vue. This component has a variable which should be set by the App.vue file. How can i achieve this?
This is my App.vue file:
<template>
<div id="app">
<Icon iconUrl="../assets/img/plant-icon-1.svg" iconAlt="Blume"/>
</div>
</template>
<script>
import Icon from './components/Icon.vue'
export default {
name: 'app',
components: {
Icon
}
}
</script>
and there's my Icon.vue file:
<template>
<div class="container iconBar">
<div class="row">
<div class="col text-center py-5">
<img :src="{ iconUrl }" :alt="{ iconAlt }">
</div>
</div>
</div>
</template>
What am i missing? Nothing is generated in the frontend. It's just empty.
UPDATE
As suggested i edited my Icon.vue like this. But still NO output. In the frontend i get an empty image and an [object Object] output in the alt-Tag
<template>
<div class="container iconBar">
<div class="row">
<div class="col text-center py-5">
<img :src="{ iconUrl }" :alt="{ iconAlt }">
</div>
</div>
</div>
</template>
<script>
export default {
props: {
iconUrl: {
type: String,
required: true
},
iconAlt: {
type: String,
required: true
}
}
}
</script>
UPDATE 2
Now it works. The fault was that i called an object and not the string. Therefore you have to write
<img :src="iconUrl" :alt="iconAlt">
instead of
<img :src="{ iconUrl }" :alt="{ iconAlt }">
Thanks everyone!