nuxt3使用 axios 进行 ssr 渲染
Sonder
2022-07-07
686字
2分钟
浏览 (5.3k)
两张图片
<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>