-1👍
They’ll be the same, because you calling URL with same data: id = 1
. You need to use props for your component:
Vue.component('show-title', {
props: ['id'], // here you defined props
mounted(){
fetch('https://jsonplaceholder.typicode.com/todos/'+this.id) // here you fetch todo with ID from props.
.then(response => response.json())
.then(json => this.title = json.title);
},
data: function () {
return {
title: "hello world!"
}
},
template:"<h3>{{title}}</h3>"
});
In your template add :id
:
<show-title :id="1"></show-title>
<show-title :id="2"></show-title>
<show-title :id="3"></show-title>
Source:stackexchange.com