vue如何根據(jù)網(wǎng)站路由判斷頁面主題色詳解
更新時間:2018年11月02日 15:26:05 作者:anne_zhou
這篇文章主要給大家介紹了關于vue如何根據(jù)網(wǎng)站路由判斷頁面主題色的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
前言
本文主要介紹的是vue根據(jù)網(wǎng)站路由判斷頁面主題色的相關內(nèi)容,分享出來供大家參考學習,下面話不多說了,來一起看看詳細的介紹吧
需求:
不同品牌對應不同版本配色
做法:
根據(jù)域名帶的參數(shù)判斷進入哪個品牌,對應哪個版本
在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>
總結
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
相關文章
vue路由篇之router-view內(nèi)容無法渲染出來問題
這篇文章主要介紹了vue路由篇之router-view內(nèi)容無法渲染出來問題及解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04
vue安裝和使用scss及sass與scss的區(qū)別詳解
這篇文章主要介紹了vue安裝和使用教程,用了很久css預編譯器,但是一直不太清楚到底用的sass還是scss,直到有天被問住了有點尷尬,感興趣的朋友一起看看吧2018-10-10
vue使用天地圖、openlayers實現(xiàn)多個底圖疊加顯示效果
這篇文章主要介紹了vue使用天地圖、openlayers實現(xiàn)多個底圖疊加顯示,根據(jù)返回的經(jīng)緯度列表通過天地圖、openlayers實現(xiàn)底圖添加,本文通過示例代碼給大家介紹的非常詳細,需要的朋友參考下吧2022-04-04

