问题描述:
在nuxt中使用useFetch时,发现切换页面后,服务器端渲染的接口,跑到浏览器里执行了:
经过搜索排查发现:nuxt仅在首屏是服务器端渲染的结果,后面走NuxtLink跳转的,全都是spa单页应用(也就是vue在浏览器请求并渲染)
我现在临时把NuxtLink换成了链接a。
问一下大佬们,有其他方案吗?
// 修改前
<NuxtLink to="/news">资讯</NuxtLink>
// 修改后
<a href="/news">资讯</a>news.vue
<template>
{{list.length}}
</template>
<script setup>
const {data: newsData} = await useFetch('/news.json', {
method: 'POST',
body: {
type: 0
}
})
const list = newsData?._value?.data || [];
</script>