I am pretty new to Vue.js and have a question.
First I have this code to get all the data from my backend application:
var app2 = new Vue({
delimiters: ['%%', '%%'],
el: '#app2',
data: {
articles: []
},
mounted : function()
{
this.loadData();
},
methods: {
loadData: function() {
this.$http.get('/backend/FpArticle/articleApi').then(response => {
// get body data
this.articles = response.body;
}, response => {
// error callback
});
},
},
I guess this is pretty straightforward. Now I display the data in articles on the frontend in a table view. So I do something like this:
<tr v-for="article in articles">
<td>{{ article.name }}</td>
</tr>
This works. But now I want to create an edit mask where the user can change some data elements of this article. So I assume to do something like this:
<tr v-for="article in articles">
<td>{{ article.name }}</td>
<td><a href="/article/{{ article.id }}">edit</a></td>
</tr>
So I need another component that takes the id, reads the data of the article, displays it in a form and handles a save event. I think I know how I resolve the latter part, but how do I do the routing with a new component? Or is there a better way that is recommended in Vue? Something like this maybe?
<tr v-for="article in articles">
<td>{{ article.name }}</td>
<td><button v-on:click="editArticle(article.id)">edit</button></td>
</tr>
I am grateful for any tips! Thanks!
editArticle, do you try to userouter.push?