Skip to content

Instantly share code, notes, and snippets.

@szabomikierno
Last active May 26, 2020 20:36
Show Gist options
  • Select an option

  • Save szabomikierno/99d81bd7a9314898bb29e052e6c16dc9 to your computer and use it in GitHub Desktop.

Select an option

Save szabomikierno/99d81bd7a9314898bb29e052e6c16dc9 to your computer and use it in GitHub Desktop.
<template>
<div class="container">
<example-article v-for="article in articles" :article="article"></example-article>
<button @click="fixArticles()">Fix Articles</button>
<button @click="pushArticle({title: 'Third Title', content: 'Content of the third article'})">Push Article</button>
</div>
</template>
<script>
let ExampleArticle = {
props: ['article'],
template: `<div class='row'>
<h5>{{article.title}}</h5>
<p>{{article.content}}</p>
</div>`
}
export default {
components: {
'example-article': ExampleArticle
},
data () {
return {
articles: [{
title: "First Title",
content: "Content of the first alticle"
}, {
title: "Second Title",
content: "Content of the second alticle"
}],
}
},
methods: {
fixArticles() {
for (var i = this.articles.length - 1; i >= 0; i--) {
this.articles[i].content = this.articles[i].content.replace("alticle", "article")
}
},
pushArticle(article) {
this.articles[this.articles.length] = article
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment