Reputation: 49
I need help. I have array of objects in one component (projects.vue) "/projects". I want to pass that values to another component(details.vue) "/details". In those objects, I have "id" property and "name" property. So - the goal is to make template in details.vue, which can display "name" properties of those objects, for example - <h1>{{projects[1].name}}</h1>
.
Id must be used as key value.
In details.vue, I have following method:
created() {
this.$http.get('/projects/' + this.id)
.then(function(data){
// console.log(data)
this.project = data.body;
console.log(data.body)
})
}
I'm new with vue-router and confused. Thanks in advance.
Upvotes: 0
Views: 200
Reputation: 2644
You have multiple options, you could use vuex to persist the data for the lifetime of your application (and share it between components).
You could also send the data as route parameters, or use a different service to store the data.
However I generally advise to do such tasks with vuex.
Upvotes: 1