单页应用动态设置页面title
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的更多相关文章
- vue动态设置页面title方法
第一种方法 npm install vue-wechat-title --save 在mian.js中引入 //设置title import VueWechatTitle from 'vue-wech ...
- 【转】移动Web单页应用开发实践——页面结构化
1. 前言 在开发面向现代智能手机的移动Web应用的时候,无法避免一个事实,就是需要开发单页应用(Single Page WebApp).对于不同的系统需求,单页应用的粒度会不同,可能是整个系统都使用 ...
- 移动Web单页应用开发实践——页面结构化
1. 前言 在开发面向现代智能手机的移动Web应用的时候,无法避免一个事实,就是需要开发单页应用(Single Page WebApp).对于不同的系统需求,单页应用的粒度会不同,可能是整个系统都使用 ...
- 小程序之--动态设置页面标题 wx.setNavigationBarTitle
参考地址 http://www.yilingsj.com/xwzj/2018-11-26/weixin-navigationbartitletext.html 页面最初是[在线教研] 可以在这个页面的 ...
- 基于Vue的SPA动态修改页面title的方法
最近基于VUE做个SPA手机端web发现动态修改页面标题通过document.title=xxxx 来修改着实蛋疼,而且在IOS的微信端据说没效果.百度发现要针对IOS的微信做点额外的操作,即:创建一 ...
- VUE-CLI 设置页面title
router > index.js { path: '/worklist', name: 'worklist', component: worklist, meta: {title:'维修工列表 ...
- (转)asp.net动态设置标题title 关键字keywords 描述descrtptions
方法一 if (!IsPostBack){//Page title网页标题Page.Title = “我的网站标题”;//须将网页head标签设成服务器控件模式,即<head runat=&qu ...
- Vue 部署单页应用,刷新页面 404/502 报错
在 Vue 项目中,可以选择 hash或者 history.pushState() 实现路由跳转.如果在路由中使用history模式: export default new Router({ mode ...
- asp.net动态设置标题title 关键字keywords 描述descrtptions
推荐的简单做法如下: protected void Page_Load(object sender, EventArgs e){//Page titlePage.Title = "This ...
随机推荐
- VS2013 堆栈溢出调查(0xC00000FD: Stack overflow)
在调试一个代码时,执行过程中会出现如下错误(0xC00000FD: Stack overflow). 很明显是堆栈溢出了. 网上很多方法,都是通过修改设置工程配置,把堆栈调大一些,如下图. 但是堆栈到 ...
- 双击表,powerdesigner pdm 没有 comment列(no comment)
- Qt QFile文件读写
QFile 需要添加 #Include <QFile> 集成至QIODevice 打开一个文件有3种方式QIODevice::(ReadOnly/WriteOnly/ReadWrite) ...
- Codeforces Round #436 (Div. 2) D. Make a Permutation!
http://codeforces.com/contest/864/problem/D 题意: 给出n和n个数(ai <= n),要求改变其中某些数,使得这n个数为1到n的一个排列,首先保证修改 ...
- [LeetCode] Longest Harmonious Subsequence 最长和谐子序列
We define a harmonious array is an array where the difference between its maximum value and its mini ...
- [LeetCode] Max Consecutive Ones 最大连续1的个数
Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...
- Caffe+VS2015+python3的安装(基于windows)
在网上找了许多安装Caffe的教程 感觉全都是杂乱无章的 而且也没有详细的 只能自己当小白鼠来实验一次了 本次配置:CUDA 8.0+ CUDNN +VS 2015 +Python 3.5 + Ca ...
- 【JAVA】pdf转图片
最近java项目中使用到了pdf转图片的需求,在此记录一下. 1.基于GhostScript p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px ...
- Lazy Loading | Explicit Loading | Eager Loading in EntityFramework and EntityFramework.Core
EntityFramework Eagerly Loading Eager loading is the process whereby a query for one type of entity ...
- [Codeforces 864A]Fair Game
Description Petya and Vasya decided to play a game. They have n cards (n is an even number). A singl ...