Coming from a React development environment, I'm challenging myself to learn some Vue at the moment. However, I'm stuck with some problems to pass data along as props between components.
My objective is to display strings out of a list as
elements, which later I'll animate with transitions. For this, I created a Vue project using the Vue Cli and additional libraries include only Bootstrap and Router.
I just can't make this to work...
So I have a main.js containing my paths and :
new Vue({
router,
data: {
listOfStrings: ['test1 test1', 'test2', 'test3']
},
render: h => h(App),
}).$mount('#app')
I also have a Home.vue containing a region with a big image, where I want to put the sentences from the list.
<template>
<div class="homelander">
<div class="container">
<TextHome/>
</div>
</div>
</template>
<script>
import TextHome from '../components/TextHome.vue'
export default {
name: 'Home',
components: {
TextHome
}
</script>
}
And finally, I have a TextHome component, which I actually would like to reuse by being able to pass the list containing the strings as props.
TextHome.vue
<div v-for="item in listOfStrings" v-bind:key="item">
<p>{{item}}</p>
</div>
It doesn't matter what I try, the list is, undefined, or I get "Property or method "listOfStrings" is not defined on the instance but referenced during render.", or even an error due to keys missing for each char from the string... So, yeah.. I'm very confused... If anyone could shed some light on this mess, I would be grateful.