nuxt.config.ts 中的 ssr 也是 true
自己写的后台接口
页面显示正常的,但是右键, 查看源代码后里面没有请求回来的数据呀!
这能 SEO ?
nuxt.config.ts 代码:
export default defineNuxtConfig({
app: {
head: {
charset: 'utf-8',
viewport: 'width=device-width, initial-scale=1',
}
},
devtools: {enabled: false},
//关闭遥测数据
telemetry: false,
modules: ['@pinia/nuxt'],
css: [
"@/assets/style/style.css" //配置使用的样式
],
ssr:true,
})
页面代码:
<template>
<div id="body">
<div class="container">
<div id="main">
<article class="post" v-if="_length(row)>0">
<h1 class="center">{{row.title}}</h1>
<ul class="post-meta">
<li>
<time>{{dateDisplay(row.created_at)}}</time>
</li>
<li><a :href="row.url">默认分类</a>
</li>
<li><a>{{row.views}}</a> 阅读</li>
<li><a href="#comments">评论</a></li>
</ul>
<div class="post-content" v-html="row.content"></div>
<p class="tags">标签: <a v-for="tag in row.tag" :href="getTagUrl(tag)">{{tag}}</a></p>
<div class="post-near">
<li class="post-left">没有了</li>
<li class="post-right">没有了</li>
</div>
<div class="clearfix"></div>
</article>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import {onMounted,ref} from "vue";
import {getArticleDetail} from "~/api/article";
import type {ApiResponse,ArticleItem} from "~/types/interface";
import {dateDisplay} from "~/utils/date";
import {_length} from "~/utils";
import { useRoute } from '#app';
const route = useRoute();
const params = route.params;
const id = ref(params.id);
const loading = ref(false);
const row = ref<ArticleItem>();
onMounted(async()=>{
await fetchData();
})
const fetchData = async() =>{
try {
loading.value = true;
const data:ApiResponse = await getArticleDetail({id:id.value});
if(data.code!==0){
return Promise.reject(data.message);
}
row.value = data.data as ArticleItem;
if(_length(row.value.url)===0){
row.value.url = '/archives/'+row.value.slug;
}
useHead({
title: row.value.title,
meta: [
{ name: 'description', content: '我的神奇网站。' }
],
bodyAttrs: {
class: 'test'
},
script: [ { innerHTML: 'console.log(\'Hello world\')' } ]
})
}catch (e) {
loading.value = false;
}
}
</script>
<style scoped lang="less">
</style>
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.