javascript - vue2.0如何設(shè)置 網(wǎng)頁標(biāo)題 關(guān)鍵字 描述
問題描述
vue2.0如何設(shè)置 網(wǎng)頁標(biāo)題title 和meta標(biāo)簽里面的 關(guān)鍵字和描述呢?想動態(tài)改變,切換路由或者其他情況下,動態(tài)改變這三個地方
問題解答
回答1:在router.js中如下設(shè)置
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:
入口文件 的 基本標(biāo)簽都是可以被操作的 你可以在 Router router.beforeEach((to, from, next) => {//這里操作DOM // .../* console.log(to); console.log(from);*/ next();})
相關(guān)文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. PHP求助,求幫忙謝謝各位3. extra沒有加載出來4. mysql - php 如何網(wǎng)址中出現(xiàn)該頁標(biāo)題?5. javascript - 天貓首頁首屏數(shù)據(jù)來源6. javascript - 釘釘?shù)膃xcel, word文件預(yù)覽是直接用的微軟的office web app,不犯法嗎?7. 關(guān)于Mysql數(shù)據(jù)表行轉(zhuǎn)列8. django進(jìn)行數(shù)據(jù)庫的查詢9. 求救一下,用新版的phpstudy,數(shù)據(jù)庫過段時間會消失是什么情況?10. mysql - 為什么where條件中or加索引不起作用?
