vue2.0动态改变index中title

第一种

let setDocumentTitle = function (title) {
    document.title = title;
    let ua = navigator.userAgent;
    if (/\bMicroMessenger\/([\d\.]+)/.test(ua) && /ip(hone|od|ad)/i.test(ua)) {
        var i = document.createElement('iframe');
        i.src = '/favicon.ico';
        i.style.display = 'none';
        i.onload = function () {
            setTimeout(function () {
                i.remove();
            }, 9);
        };
        document.body.appendChild(i);
    }
};

路由跳转前

// 路由跳转前进行title设置
router.beforeEach((to, from, next) => {
  setDocumentTitle(to.meta.pageTitle)
  next()
})

第二种

https://github.com/deboyblog/vue-wechat-title

你可能感兴趣的:(vue-js)