首页html.js
<title></title>
<meta name="keywords" content="" />
<meta name="description" content="">
路由router/indexjs
const routes = [{
path: "/index",
name: "index",
component: () =>
import ("../views/Index.vue"),
meta: {
title: "首页",
content: {
keywords: '关键词',
description: '描述'
}
}
}]
main.js
router.beforeEach((to, from, next) => {
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)
}
if (to.meta.title) {
document.title = to.meta.title;
}
next()
});
以上是编程学习网小编为您介绍的“vuejs动态设置每个页面的标题、关键词和描述”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。
沃梦达教程
本文标题为:vuejs动态设置每个页面的标题、关键词和描述
猜你喜欢
- 详解SPA中前端路由基本原理与实现方式 2024-02-20
- javascript学习随笔(使用window和frame)的技巧 2023-12-24
- JavaScript中windows.open()、windows.close()方法详解 2023-11-30
- Django中的Ajax 2022-12-15
- moment转化时间戳出现Invalid Date的问题及解决 2023-07-09
- wepy微信小程序框架加入版本更新提示 2022-10-29
- alt属性和title属性 2022-10-16
- JavaScript 设计模式中的代理模式详解 2022-08-31
- Vue3使用富文本编辑器QuillEditor 2023-10-08
- php – 从数据库生成静态HTML文件 2023-10-26