vue+ts设置网页title

在router.js/router.ts中增加

javascript 复制代码
router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  var Document:any = document;
  console.log(from, Document);
  if (to.meta.title) {
    Document.title = to.meta.title;
  }
  next()
})

在路由中设置

javascript 复制代码
const routes = [
  {
    path: "/login",
    name: "LoginPage",
    meta: { requiresAuth: false, hideSidebar: true,title: '登录界面' }, 
    component: LoginPage,
  },
]

之前那些windows.document.title,都用不了,得先定义:var Document:any = document;

相关推荐
kyriewen113 小时前
你点的“刷新”是假刷新?前端路由的瞒天过海术
开发语言·前端·javascript·ecmascript·html5
摇滚侠4 小时前
JAVA 项目教程《苍穹外卖-12》,微信小程序项目,前后端分离,从开发到部署
java·开发语言·vue.js·node.js
Timer@4 小时前
LangChain 教程 04|Agent 详解:让 AI 学会“自己干活“
javascript·人工智能·langchain
阿珊和她的猫4 小时前
TypeScript中的never类型: 深入理解never类型的使用场景和特点
javascript·typescript·状态模式
九皇叔叔8 小时前
003-SpringSecurity-Demo 统一响应类
java·javascript·spring·springsecurity
低代码布道师10 小时前
纯代码实战:MBA培训管理系统 (十四) ——用户管理(批量选择与批量删除)
javascript·nextjs
打瞌睡的朱尤10 小时前
建立vue项目
vue.js
Hello--_--World11 小时前
JavaScript运行机制、v8原理、js事件循环
开发语言·javascript·ecmascript
bearpping12 小时前
Spring Boot + Vue 全栈开发实战指南
vue.js·spring boot·后端
可问春风_ren12 小时前
HTML零基础进阶教程:解锁表单、多媒体与语义化实战
前端·git·html·ecmascript·reactjs·js