-
-
Save cursosdesarrolloweb/9fbf0effabca4d32f986979d68b8db26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vue.component('fetch', { | |
data () { | |
return { | |
users: [] | |
} | |
}, | |
async mounted() { | |
const response = await fetch('https://jsonplaceholder.typicode.com/users'); | |
this.users = await response.json() | |
} | |
}, | |
template: ` | |
<div> | |
<h2>Fetch con Vue 2</h2> | |
<ul v-if="users.length"> | |
<li v-for="user in users" :key="user.id"> | |
{{ user.name }} - {{ user.email }} | |
</li> | |
</ul> | |
<p v-else>No hay usuarios disponibles</p> | |
</div> | |
` | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.component("fetch", { | |
setup () { | |
const users = ref([]); | |
onMounted(async () => { | |
const response = await fetch("https://jsonplaceholder.typicode.com/users"); | |
users.value = await response.json() | |
}); | |
return { users }; | |
}, | |
template: ` | |
<h2>Fetch en Vue 3</h2> | |
<ul v-if="users.length"> | |
<li v-for="user in users" :key="user.id"> | |
{{ user.name }} - {{ user.email }} | |
</li> | |
</ul> | |
<p v-else>No hay usuarios disponibles</p> | |
` | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment