You can easily add this logic in App.vue too.
Last active
April 28, 2022 11:22
-
-
Save howbizarre/ff4e16e761f595dea0745ee176dea8d1 to your computer and use it in GitHub Desktop.
Nuxt 3 async calls to /server/api/ from view in /pages/
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
/** | |
* add in "/server/api/" folder as "async.ts" | |
* or rename it as you wish | |
* ref: https://jsonplaceholder.typicode.com/ | |
**/ | |
export default defineEventHandler(async (): Promise<any> => { | |
return await $fetch("https://jsonplaceholder.typicode.com/posts"); | |
}); |
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
<script setup lang="ts"> | |
const rspns = $fetch("/api/async"); | |
rspns.then((data) => console.log("data: ", data)); | |
</setup> | |
<template> | |
<div>Check browser's console for logs</div> | |
</template> | |
<style> | |
/** | |
* add in "/pages/" folder as "index.vue" | |
**/ | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment