84669 人學習
152542 人學習
20005 人學習
5487 人學習
7821 人學習
359900 人學習
3350 人學習
180660 人學習
48569 人學習
18603 人學習
40936 人學習
1549 人學習
1183 人學習
32909 人學習
vue2.0如何設定 網頁標題title 和meta標籤裡面的 關鍵字和描述呢?想動態改變,切換路由或在其他情況下,動態改變這三個地方
在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') })
入口檔案的基本標籤都是可以被操作的你可以在Router router.beforeEach((to, from, next) => {//這裡操作DOM // .../* console.log (to); console.log(from);*/ next();})
在router.js中如下設定
入口檔案的基本標籤都是可以被操作的
你可以在Router
router.beforeEach((to, from, next) => {
//這裡操作DOM
// ...
/* console.log (to);
console.log(from);*/
next();
})