javascript - vue2.0如何設(shè)置 網(wǎng)頁標(biāo)題 關(guān)鍵字 描述
問題描述
vue2.0如何設(shè)置 網(wǎng)頁標(biāo)題title 和meta標(biāo)簽里面的 關(guān)鍵字和描述呢?想動(dòng)態(tài)改變,切換路由或者其他情況下,動(dòng)態(tài)改變這三個(gè)地方
問題解答
回答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: ’注冊(cè)’ } } ]})// 全局配置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. MySQL主鍵沖突時(shí)的更新操作和替換操作在功能上有什么差別(如圖)2. 關(guān)于mysql聯(lián)合查詢一對(duì)多的顯示結(jié)果問題3. python中如何計(jì)算t分布的值?4. mysql在限制條件下篩選某列數(shù)據(jù)相同的值5. 數(shù)據(jù)庫 - Mysql的存儲(chǔ)過程真的是個(gè)坑!求助下面的存儲(chǔ)過程哪里錯(cuò)啦,實(shí)在是找不到哪里的問題了。6. python執(zhí)行cmd命令,怎么讓他執(zhí)行類似Ctrl+C效果將其結(jié)束命令?7. python - scrapy url去重8. 實(shí)現(xiàn)bing搜索工具urlAPI提交9. python - Django有哪些成功項(xiàng)目?10. Python從URL中提取域名
