I'm trying to learn Vue.js(2) by building a simple RSS reader. I've moved past the initial single component view and am now trying to refactor my code into a component (RSSFeed) with repeating sub-components (FeedPost).
App.vue
|
|
RSSFeed.vue
|
|
FeedPost.vue
I've managed the make the component bind to a repeating element but can't get the data to correctly appear. Currently the rendered HTML shows the following result:
<ol data-v-f1de79a0="" id="feed">
<li data-v-f1de79a0="" post="[object Object]" class="RSSFeed"></li>
<li data-v-f1de79a0="" post="[object Object]" class="RSSFeed"></li>
...
<li data-v-f1de79a0="" post="[object Object]" class="RSSFeed"></li>
</ol>
I believe the error is around my props element but I'm unsure on where I've strayed from Components Basics Guide. A shortened version of the JSON returned by my app server is here.
RSSFeed.vue
<template>
<ol id="feed">
<li class="RSSFeed"
v-for="item in items"
v-bind:key="item.indexOf"
v-bind:post="item">
</li>
</ol>
</template>
<script>
import axios from 'axios'
import Post from './Post'
export default {
name: 'RSSFeed',
props: {Post},
data () {
return {
items: [],
errors: []
}
},
created () {
axios.get(`http://localhost:5000/rss/api/v1.0/feed`)
.then(response => {
// JSON responses are automatically parsed.
this.items = response.data.rss.channel.item
})
.catch(e => {
this.errors.push(e)
})
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
Post.vue
<template>
<div id="post">
{{post.title}}
{{post.pubDate}}
{{description}}
{{link}}
</div>
</template>
<script>
export default {
name: 'Post',
prop: ['post']
}
</script>
<style scoped>
</style>