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

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!