1.适用场景:所有通过router路由的单页应用。

2.示例代码:本文以vue-router为例。

 在router.js中:

let router = new Router({
routes: [
{
path: '/',
title: '',
redirect: '/chooseCity'
},
{
path: '/login',
title: '',
component: resolve => require(['components/login/login.vue'], resolve)
},
{
path: '/register',
title: '',
component: resolve => require(['components/login/register.vue'], resolve)
},
{
path: '/updatePassword',
title: '',
component: resolve => require(['components/login/updatePassword.vue'], resolve)
},
{
path: '/home',
title: '',
component: resolve => require(['components/home/home.vue'], resolve)
},
{
path: '/user',
title: '',
component: resolve => require(['components/user/user.vue'], resolve)
},
{
path: '/orderList',
title: '',
component: resolve => require(['components/orderList/orderList.vue'], resolve)
},
{
path: '/order',
title: '',
component: resolve => require(['components/order/order.vue'], resolve)
},
{
path: '/orderDetail',
title: '',
component: resolve => require(['components/orderDetail/orderDetail.vue'], resolve)
},
{
path: '/pay',
title: '',
component: resolve => require(['components/pay/pay.vue'], resolve)
},
{
path: '/chooseCinema',
title: '',
component: resolve => require(['components/chooseCinema/chooseCinema.vue'], resolve)
},
{
path: '/serviceRule',
title: '',
component: resolve => require(['components/serviceRule/serviceRule.vue'], resolve)
},
{
path: '/chooseCity',
title: '',
component: resolve => require(['components/chooseCity/chooseCity.vue'], resolve)
}
],
mode: 'history',
base: '/order/'
});
router.afterEach((transition) => {
// let name = transition.name;
// let item = router.options.routes.filter((ele) => { return ele.name === name; });
Tool.setTitle('哈哈哈哈');
});
export default router; 3.需要用到工具Tool.setTitle:
/**
* 设置页面标题
*/
function setTitle(title) {
document.title = title
var mobile = navigator.userAgent.toLowerCase();
if (/iphone|ipad|ipod/.test(mobile)) {
var iframe = document.createElement('iframe');
iframe.style.display = 'none'
var iframeCallback = function () {
setTimeout(function () {
iframe.removeEventListener('load', iframeCallback);
document.body.removeChild(iframe);
}, 0);
}
iframe.addEventListener('load', iframeCallback);
document.body.appendChild(iframe);
}
}

												

单页应用动态设置页面title的更多相关文章

  1. vue动态设置页面title方法

    第一种方法 npm install vue-wechat-title --save 在mian.js中引入 //设置title import VueWechatTitle from 'vue-wech ...

  2. 【转】移动Web单页应用开发实践——页面结构化

    1. 前言 在开发面向现代智能手机的移动Web应用的时候,无法避免一个事实,就是需要开发单页应用(Single Page WebApp).对于不同的系统需求,单页应用的粒度会不同,可能是整个系统都使用 ...

  3. 移动Web单页应用开发实践——页面结构化

    1. 前言 在开发面向现代智能手机的移动Web应用的时候,无法避免一个事实,就是需要开发单页应用(Single Page WebApp).对于不同的系统需求,单页应用的粒度会不同,可能是整个系统都使用 ...

  4. 小程序之--动态设置页面标题 wx.setNavigationBarTitle

    参考地址 http://www.yilingsj.com/xwzj/2018-11-26/weixin-navigationbartitletext.html 页面最初是[在线教研] 可以在这个页面的 ...

  5. 基于Vue的SPA动态修改页面title的方法

    最近基于VUE做个SPA手机端web发现动态修改页面标题通过document.title=xxxx 来修改着实蛋疼,而且在IOS的微信端据说没效果.百度发现要针对IOS的微信做点额外的操作,即:创建一 ...

  6. VUE-CLI 设置页面title

    router > index.js { path: '/worklist', name: 'worklist', component: worklist, meta: {title:'维修工列表 ...

  7. (转)asp.net动态设置标题title 关键字keywords 描述descrtptions

    方法一 if (!IsPostBack){//Page title网页标题Page.Title = “我的网站标题”;//须将网页head标签设成服务器控件模式,即<head runat=&qu ...

  8. Vue 部署单页应用,刷新页面 404/502 报错

    在 Vue 项目中,可以选择 hash或者 history.pushState() 实现路由跳转.如果在路由中使用history模式: export default new Router({ mode ...

  9. asp.net动态设置标题title 关键字keywords 描述descrtptions

    推荐的简单做法如下: protected void Page_Load(object sender, EventArgs e){//Page titlePage.Title = "This ...

随机推荐

  1. apacheds的客户端

    Apache DS管理的JAVA实现 LdapConnection connection = new LdapNetworkConnection("localhost", 1038 ...

  2. Spring Security 入门(1-8)Spring Security 的配置文件举例

  3. 115 个 Java 面试题和答案——终极(上)

    目录 面向对象编程(OOP)常见的 Java 问题Java 线程Java 集合类垃圾收集器 面向对象编程(OOP) Java 是一个支持并发.基于类和面向对象的计算机编程语言.下面列出了面向对象软件开 ...

  4. 一个适用于单页应用,返回原始滚动条位置的demo

    如题,最近做一个项目时,由于页面太长,跳转后在返回又回到初始位置,不利于用户体验,需要每次返回到用户离开该页面是的位置.由于是移动端项目,使用了移动端的套ui框架framework7,本身框架的机制是 ...

  5. Tesseract-OCR4.0识别中文与训练字库实例

    关于中文的识别,效果比较好而且开源的应该就是Tesseract-OCR了,所以自己亲身试用一下,分享到博客让有同样兴趣的人少走弯路. 文中所用到的身份证图片资源是百度找的,如有侵权可联系我删除. 一. ...

  6. [洛谷P2234][HNOI2002] 营业额统计 - Treap

    Description Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成立以来每天的营业额. ...

  7. centos7配置Apache支持HTTPS

    Apache版本2.4 安装mod_ssl yum install mod_ssl 建立文件夹,存放sslkey mkdir /etc/httpd/ssl/ 建立凭证档 openssl req -x5 ...

  8. Django多级评论

    一.原理 #多级评论原理简单原理,弄完之后发现基础白学了 msg_list = [ {'id':1,'content':'xxx','parent_id':None}, {'id':2,'conten ...

  9. LinuxMint18使用单独分区作为Home挂载点

    安装LinuxMint时,我没有为/home选择单独的分区,所以在安装完系统之后就得手动配置一番. 首先是创建一个分区,这个很简单就不说啦. 然后就是把现有的/home下的文件移动到新的分区里面 操作 ...

  10. join()的用法

    Python中有join()和os.path.join()两个函数,具体作用如下:    join():    连接字符串数组.将字符串.元组.列表中的元素以指定的字符(分隔符)连接生成一个新的字符串 ...