nuxt 서버 렌 더 링 동적 설정 title 과 seo 키워드 작업
asyncData ({ app }, callback) {
app.head.title = ‘new title'
callback(null, {})
},
추가 지식:vue 각 페이지 동적 전환 title keywords description(seo 설정)최근 에 서 를 사용 해 야 한 다 는 것 을 접 했 습 니 다.각 페이지 에 서로 다른 title,keywords,description 을 요구 합 니 다.
!!!여기에 먼저 한 단 계 를 추가 합 니 다:
html 파일 추가
첫 번 째 단 계 는 router 에서 index.js 폴 더 에 있 습 니 다.
routes: [
{
path: '/',
name: 'main',
component: Main,
meta: {
title: ' title ',
content:{
keywords:' keywords',
description:' description',
},
}
},
{
path: '/trueBag',
name: 'trueBag',
component: trueBag,
meta: {
title: 'trueBag title ',
content:{
keywords:' keywords',
description:' description',
},
}
},
]
두 번 째 단 계 는 main.js 에서 설정 합 니 다.경로 가 바 뀌 어 페이지 meta 를 수정 합 니 다.전 제 는 router 를 가 져 왔 습 니 다.
// ,
// meta, keywords description ,
// :
// setAttribute router content
//
//document.querySelector(‘meta[name=“description”]').setAttribute(‘content', to.meta.content.description)
router.beforeEach((to, from, next) => {
/* meta */
console.log(to.meta.content)
if(to.meta.content){
let head = document.getElementsByTagName('head');
let meta = document.createElement('meta');
document.querySelector('meta[name="keywords"]').setAttribute('content', to.meta.content.keywords)
document.querySelector('meta[name="description"]').setAttribute('content', to.meta.content.description)
meta.content = to.meta.content;
head[0].appendChild(meta)
}
// /* title */
if (to.meta.title) {
document.title = to.meta.title;
}
next()
});
구체 적 인 성공 여 부 는 f12 에서 확인 할 수 있 습 니 다.만약 나 오지 않 았 다 면 한 걸음 한 걸음 인쇄 해서 자신 이 어디 에 잘못 되 었 는 지 볼 수 있 습 니 다.
이상 의 nuxt 서버 렌 더 링 동적 설정 title 과 seo 키 워드 는 바로 작은 편집 이 여러분 에 게 공유 하 는 모든 내용 입 니 다.참고 하 시기 바 랍 니 다.여러분 들 이 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
【비공식】Notion을 CMS로 해 기사 일람을 취득해 보았다 【하지만 편리】최근에는 업무 위탁으로 디자인 회사에서 배우면서 일전을 벌 수 있는 생활을 하고 있습니다. 또 이 후 axios를 넣을지 묻는다고 생각하므로 잊지 않고 넣어 봅시다. 이번에는 create-nuxt-app라는 페이지를...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.