Comments (3)
在vue-router
里配置title
、style
、webview
(站内app右上角简易配置)
// router config
const getMeta = (to) => {
return Object.assign({}, to.meta, to.matched[0].meta);
}
router.beforeEach((to, form, next) => {
const toMeta = getMeta(to);
// title
if (toMeta.title) document.title = toMeta.title;
// style
if (toMeta.style) {
for (const i in toMeta.style) {
document.body.style[i] = toMeta.style[i];
}
}
// webview
if (toMeta.webview) {
bzShare.share({
app: {
bzWebviewBtn: toMeta.webview,
},
});
}
return next();
});
// page route
export default {
path: '/test',
name: 'test',
component: testComponent,
meta: {
title: 'test title',
style: {
backgroundColor: '#efeff4',
},
webview: '1100',
},
}
from blog.
App登录处理
const debug = localStorage.getItem('project_debug');
router.beforeEach((to, form, next) => {
// 是否需要登录
if (!to.meta.login) {
return next();
}
// 已有登录信息
if (store.state.user) {
return next();
}
// 兼容开发模式
const afterLogin = (callback) => {
if (debug) {
console.debug('[debug] 跳过登录逻辑');
callback && callback();
} else {
bzLogin.afterAllLogin(callback);
}
}
afterLogin(() => {
store.dispatch('getUser', {
success() {
next();
},
error(err) {
console.log(err);
}
});
});
});
from blog.
路由百度统计pv、uv处理
必须指定 location.pathname 路径,站内大部分地址代理过,如果不加会统计到M站首页根目录下面去
router.afterEach((to, from, next) => {
if (window._hmt && to.path) {
const location = window.location
const pagePath = location.pathname + '#' + to.fullPath
window._hmt.push(['_trackPageview', pagePath])
}
});
from blog.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.