需求:

不同品牌对应不同版本配色

做法:

根据域名带的参数判断进入哪个品牌,对应哪个版本

在main.js中

import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
import MintUI from 'mint-ui'
import { Indicator } from 'mint-ui'
import { getUrls } from '@/util/utils'
import 'mint-ui/lib/style.css'
import './css/index.css'
Vue.use(MintUI)
//添加请求拦截器 loading
axios.interceptors.request.use(function (config) {
Indicator.open({
text: '加载中...',
spinnerType: 'fading-circle'
})
return config
}),function (error) {
Indicator.close()
return Promise.reject(error)
}
axios.interceptors.response.use(function (config) {
Indicator.close()
return config
}),function (error) {
return Promise.reject(error)
} Vue.prototype.$http = axios
Vue.prototype.getUrls = getUrls
router.beforeEach((to,from,next) => {
if (sessionStorage.getItem('basecolor')) {
document.documentElement.style.setProperty("--color", sessionStorage.getItem('basecolor'))
next()
}
})
Vue.config.productionTip = false /* eslint-disable no-new */
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
})

  在util.js中

export function getUrls() {
let colorValue
let url = window.location.href
let urlArr = url.split('?')
let appU = urlArr[0].split('/')
let styles = getComputedStyle(document.documentElement)
if (appU[appU.length-1] === 'login') {
colorValue = styles.getPropertyValue('--OLAY')
sessionStorage.setItem('basecolor', colorValue)
this.$router.push('/login')
} else if (appU[appU.length-1] === 'resetPassword') {
colorValue = styles.getPropertyValue('--pampers')
sessionStorage.setItem('basecolor', colorValue)
this.$router.push('/login')
}
}

  在App.vue

<template>
<div id="app">
<router-view/>
</div>
</template> <script>
export default {
name: 'App',
created() {
this.getUrls()
}
}
</script> <style>
:root {
--OLAY: rgb(237,202,138);
--pampers: rgb(5,183,185);
--color: #fff;
}
#app{
height: 100%;
}
</style>

  

vue 根据网站路由判断页面主题色的更多相关文章

  1. Vue-router路由判断页面是否登录,未登录跳转到登录页面

    在index.js中 //定义路由 const router = new Router({ routes, strict: process.env.NODE_ENV !== 'production', ...

  2. Vue-router路由判断页面未登录跳转到登录页面

    router.beforeEach((to, from, next) => { if (to.matched.some(record => record.meta.requireAuth) ...

  3. 使用 css/less 动态更换主题色(换肤功能)

    前言 说起换肤功能,前端肯定不陌生,其实就是颜色值的更换,实现方式有很多,也各有优缺点 一.看需求是什么 一般来说换肤的需求分为两种: 1. 一种是几种可供选择的颜色/主题样式,进行选择切换,这种可供 ...

  4. vue项目中引入element-ui时,如何更改主题色

    在我们做项目时,我们经常会遇到切换主题色的功能,下面我们就来说一下通过颜色选择器我们就能改变项目的主题颜色 代码如下: 颜色选择器所在组件: top-theme.vue内容如下: <templa ...

  5. 「Vue」起步 - vue-router路由与页面间导航

    vue-router 我们知道路由定义了一系列访问的地址规则,路由引擎根据这些规则匹配找到对应的处理页面,然后将请求转发给页进行处理.可以说所有的后端开发都是这样做的,而前端路由是不存在"请 ...

  6. vue使用改变element-ui主题色

    每个项目的主题色一般都不一样,直接用element-ui的默认主题色似乎有点不合适,还需要自己一个一个的找元素class名然后在修改样式,非常麻烦,还容易影响到包含该类名的其他元素样式,所以需要自定义 ...

  7. vue如何配置路由 、获取路由的参数、部分刷新页面、缓存页面

    vue如何配置路由 .获取路由的参数.部分刷新页面.缓存页面:http://www.mamicode.com/info-detail-1941546.html vue-router传递参数的几种方式: ...

  8. Vue 实现动态路由及登录&404页面跳转控制&页面刷新空白解决方案

    Vue实现动态路由及登录&404页面跳转控制&页面刷新空白解决方案   by:授客 QQ:1033553122   开发环境   Win 10   Vue 2.9.6   node-v ...

  9. 如何机智判断页面是刷新还是关闭,背景:vue项目,需求:关闭页面,下次直接跳到登陆页

    最近项目有这么个需求:要在关闭当前系统的窗口的时候,退出登录, 因为如果不退出登录可能存在安全风险,其实我想说,电脑没事别借给别人活着离开工位记得一定要锁屏,其实我们设置了cookie失效时间的,过了 ...

随机推荐

  1. oc75--不可变字典NSDictionary

    // // main.m // NSDictionary // // #import <Foundation/Foundation.h> int main(int argc, const ...

  2. Linux ALSA声卡驱动之六:ASoC架构中的Machine

    前面一节的内容我们提到,ASoC被分为Machine.Platform和Codec三大部分,其中的Machine驱动负责Platform和Codec之间的耦合以及部分和设备或板子特定的代码,再次引用上 ...

  3. TeX中的引号

    #include <stdio.h> #include <math.h> // 算法竞赛的目标是编程对任意输入均得到正确的结果. // 请先独立完成,如果有困难可以翻阅本书代码 ...

  4. bzoj1951 [Sdoi2010]古代猪文 ——数论综合

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1951 题意就是要求 G^( ∑(k|n) C(n,k) ) % p,用费马小定理处理指数,卢 ...

  5. bzoj4082

    贪心+倍增 首先如果这个问题在序列上,好像可以按右端点排序,然后从起点开始向能到的最远的地方走. 但是环上不可以,因为随即一个起点可能不是最小的. 然后神思路来了:我们先将环展开倍增,再将区间按右端点 ...

  6. 69.资金管理-税率表管理extjs 页面

    1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8&quo ...

  7. C. Unusual Product(cf)

    http://codeforces.com/problemset/problem/405/C 题意: 给出一个n*n的矩阵,有q个操作,输入3时,输出A ,A等于第i行乘以第i列的对应元素的和(mod ...

  8. 一个thinkphhp的聊天类,感觉还可以

    <?phpnamespace Common\Controller;use Think\Controller;class HxController extends Controller{ /** ...

  9. eclipse-html插件的安装

    需求:需要在eclipse里面编辑html和jsp,语法高亮和语法提示,自动补全等. 1.下载GEF(依赖包): http://www.eclipse.org/downloads/download.p ...

  10. ACM_Ruin of Titanic(简单贪心)

    Ruin of Titanic Time Limit: 2000/1000ms (Java/Others) Problem Description: 看完Titanic后,小G做了一个梦.梦见当泰坦尼 ...