亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - How to set web page title keyword description in vue2.0
世界只因有你
世界只因有你 2017-06-26 10:52:29
0
2
1170

How to set the keywords and descriptions in the webpage title and meta tag in vue2.0? If you want to dynamically change, switch routes or other situations, dynamically change these three places

世界只因有你
世界只因有你

reply all(2)
黃舟

Set as follows in 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')
})
小葫蘆

The basic tags of the entry file can be manipulated
You can operate the DOM in Router
router.beforeEach((to, from, next) => {
//Manipulate DOM here
// ...
/* console. log(to);
console.log(from);*/
next();
})

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template