首页
归档
笔记
树洞
搜索
友言

文章详情

Interesting People Record Interesting.

/ JavaScript / 文章详情

nuxt3使用 axios 进行 ssr 渲染

Sonder
2022-07-07
686字
2分钟
浏览 (4.8k)

两张图片

复制代码
<template>
 <div>
   <input type="text" v-model="name">
   <button @click="refresh">发送</button>
   <br>
   {{ data }}
 </div>
</template>
复制代码
<script setup lang="ts">
import {ref} from 'vue'
import {refreshNuxtData, useAsyncData, useFetch, useLazyAsyncData} from "#app";
import axios, {AxiosRequestConfig} from 'axios';

const name = ref('aaa')

const {data, refresh} = await useAsyncData('name', async () => {
 const res = await axios.get('http://localhost:3000/api/hello', {
   params: {
     name: name.value
   }
 })
 console.log(res.data)
 return res.data
})

</script>
3QALOKF8NMSGX2`DZ_DUYSJ.jpg
CF__IAM_~C5U267YKNXF2QI.jpg
下一篇 / nuxt3使用pinia🍍

🎯 相关文章

💡 推荐文章

🕵️‍♂️ 评论 (0)