javascript - vue2.0如何設置 網頁標題 關鍵字 描述
問題描述
vue2.0如何設置 網頁標題title 和meta標簽里面的 關鍵字和描述呢?想動態改變,切換路由或者其他情況下,動態改變這三個地方
問題解答
回答1:在router.js中如下設置
import Vue from ’vue’import Router from ’vue-router’Vue.use(Router)const router = new Router({ routes: [{ path: ’/login’, component: Login, meta: { title: ’登錄’ } }, { path: ’/register’, component: Register, meta: { title: ’注冊’ } } ]})// 全局配置router.beforeEach((to, from, next) => { // Change doc title document.title = to.meta.title || ’Unknow title’ document.querySelector(’meta[name='keywords']’).setAttribute(’content’, ’keywords’) document.querySelector(’meta[name='description']’).setAttribute(’content’, ’description’)})回答2:
入口文件 的 基本標簽都是可以被操作的 你可以在 Router router.beforeEach((to, from, next) => {//這里操作DOM // .../* console.log(to); console.log(from);*/ next();})
相關文章:
1. html - 如何刪除css文件中沒有被引用的類?2. 關于Apache無法啟動的程序的方式是怎么解決的3. android - 在微信瀏覽器中可以在線預覽pdf嗎?4. android - 怎樣才能在連接本地WIFI是通過 3G/4G 實現微信分享?5. android - 求 360瀏覽器 百度瀏覽器 搜狗瀏覽器的最新啟動類名6. CSS 的 ID 和 Class 有什么區別?如何正確使用它們?7. vue.js - vue 打包后 nginx 服務端API請求跨域問題無法解決。8. node.js - windows7下安裝淘寶鏡像和webpack9. nginx - 使用wordpress搭建博客,怎么實現真實服務器使用HTTP,然后使用UPYUN的HTTPS加密?10. nginx - 【win7】80 端口本機可訪問,同內網其他機器不能訪問,未被占用!
