vue如何根據(jù)網(wǎng)站路由判斷頁(yè)面主題色詳解
前言
本文主要介紹的是vue根據(jù)網(wǎng)站路由判斷頁(yè)面主題色的相關(guān)內(nèi)容,分享出來(lái)供大家參考學(xué)習(xí),下面話(huà)不多說(shuō)了,來(lái)一起看看詳細(xì)的介紹吧
需求:
不同品牌對(duì)應(yīng)不同版本配色
做法:
根據(jù)域名帶的參數(shù)判斷進(jìn)入哪個(gè)品牌,對(duì)應(yīng)哪個(gè)版本
在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) //添加請(qǐng)求攔截器 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') } }
在A(yíng)pp.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>
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
相關(guān)文章
Vue3如何獲取proxy對(duì)象的值而不是引用的方式
這篇文章主要介紹了Vue3如何獲取proxy對(duì)象的值而不是引用的方式,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-10-10淺談vue-router2路由參數(shù)注意的問(wèn)題
下面小編就為大家?guī)?lái)一篇淺談vue-router2路由參數(shù)注意的問(wèn)題。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11vue路由篇之router-view內(nèi)容無(wú)法渲染出來(lái)問(wèn)題
這篇文章主要介紹了vue路由篇之router-view內(nèi)容無(wú)法渲染出來(lái)問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04vue使用Google地圖的實(shí)現(xiàn)示例代碼
這篇文章主要介紹了vue使用Google地圖的實(shí)現(xiàn)示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-12-12vue安裝和使用scss及sass與scss的區(qū)別詳解
這篇文章主要介紹了vue安裝和使用教程,用了很久css預(yù)編譯器,但是一直不太清楚到底用的sass還是scss,直到有天被問(wèn)住了有點(diǎn)尷尬,感興趣的朋友一起看看吧2018-10-10vue使用天地圖、openlayers實(shí)現(xiàn)多個(gè)底圖疊加顯示效果
這篇文章主要介紹了vue使用天地圖、openlayers實(shí)現(xiàn)多個(gè)底圖疊加顯示,根據(jù)返回的經(jīng)緯度列表通過(guò)天地圖、openlayers實(shí)現(xiàn)底圖添加,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧2022-04-04Vue中引入使用patch-package為依賴(lài)打補(bǔ)丁問(wèn)題
這篇文章主要介紹了Vue中引入使用patch-package為依賴(lài)打補(bǔ)丁問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03Vue 進(jìn)入/離開(kāi)動(dòng)畫(huà)效果
這篇文章主要介紹了Vue 進(jìn)入/離開(kāi)動(dòng)畫(huà)效果,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-12-12