img

nuxt3使用 axios 进行 ssr 渲染

2022-07-07 0条评论 3.7k次阅读 JavaScript


两张图片

<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

💬 COMMENT


🦄 支持markdown语法

👋友