關(guān)于vue.js如何根據(jù)網(wǎng)站路由判斷頁(yè)面主題色教程詳解
文章主要給大家介紹了關(guān)于vue如何根據(jù)網(wǎng)站路由判斷頁(yè)面主題色的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,...
本文主要介紹的是vue根據(jù)網(wǎng)站路由判斷頁(yè)面主題色的相關(guān)內(nèi)容,分享出來(lái)供大家參考學(xué)習(xí),下面話不多說(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)求攔截器 loadingaxios.interceptors.request.use(function(config) {Indicator.open({text:'加載中...',spinnerType:'fading-circle'})returnconfig}),function(error) {Indicator.close()returnPromise.reject(error)}axios.interceptors.response.use(function(config) {Indicator.close()returnconfig}),function(error) {returnPromise.reject(error)}Vue.prototype.$http = axiosVue.prototype.getUrls = getUrlsrouter.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 */newVue({el:'#app',router,components: { App },template:'<App/>'})
在util.js中
exportfunctiongetUrls() {let colorValuelet url = window.location.hreflet 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')}elseif(appU[appU.length-1] ==='resetPassword') {colorValue = styles.getPropertyValue('--pampers')sessionStorage.setItem('basecolor', colorValue)this.$router.push('/login')}}
在App.vue
<template><divid="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ú)相關(guān)信息
分享到:
投訴收藏

