Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit 7f210b3

Browse files
authored
Merge pull request #1 from ICJIA/11-20-2023
simple api call
2 parents d6ee447 + 03c09b2 commit 7f210b3

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

src/App.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default {
3636
</div>
3737
<div id="'app"></div>
3838
<Todo />
39-
39+
<test />
4040
</div>
4141
</template>
4242
<style scoped>

src/components/test.vue

+30-31
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,40 @@
11
<script>
2+
import axios from "axios";
23
export default {
3-
data(){
4-
return {
5-
newTask:'',
6-
tasks: [],
7-
};
4+
name: "App",
5+
data()
6+
{
7+
return{
8+
data:null,
9+
numberOfColumns:2,
10+
};
11+
},
12+
methods:{
13+
fetchData(){
14+
axios.get('https://jsonplaceholder.typicode.com/todos').then(response=>{this.data=response.data}).catch(error=>{console.error('Error fetching data',error);
15+
});
816
},
9-
methods:{
10-
addTask(){
11-
if(this.newTask.trim()!==''){
12-
this.tasks.push(this.newTask.trim());
13-
this.newTask='';
14-
}
15-
},
16-
removeTask(index){
17-
this.tasks.splice(index,1);
18-
},
19-
},
20-
17+
},
2118
};
2219
</script>
2320

2421
<template>
2522
<div>
26-
<div>
27-
<p>Message is: {{ message }}</p>
28-
<input v-model="message" placeholder="edit me" />
29-
</div>
30-
<div>
31-
<input v-model="newTask" @key.enter="addTask" placeholder="Add a new Task">
32-
<button @click="addTask">Add</button>
33-
</div>
34-
<ul>
35-
<li v-for="(task,index) in tasks " :key ="index">
36-
{{ task }}
37-
<button @click="removeTask(index)">Remove</button>
38-
</li>
39-
</ul>
23+
24+
<button @click="fetchData">FetchData</button>
25+
<table v-if="data">
26+
<thead>
27+
<tr>
28+
<th>ID</th>
29+
<th>title</th>
30+
</tr>
31+
</thead>
32+
<tbody>
33+
<tr v-for="item in data" :key="item.id">
34+
<td>{{ item.id }}</td>
35+
<td :colspan="5">{{ item.title }}</td>
36+
</tr>
37+
</tbody>
38+
</table>
4039
</div>
4140
</template>

0 commit comments

Comments
 (0)