You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
import Vue from 'vue' import VueResource from 'vue-resource' Vue.use(VueResource)
import themeArray from './themeArray'
// 封装一些全局元素。如全站通用功能函数和http请求等
export const global = { staticPath: process.env.NODE_ENV === 'development' ? '.' : './', /** * 切换主题函数 */ changeTheme: function(themeValue) { var that = this
// console.log('切换主题颜色值:', themeValue, that.staticPath, JSON.stringify(themeArray))
// 需要移到单独的文件存放
var cssArray = themeArray removeCss() for (let i = 0, len = cssArray.length; i < len; i++) { var itemPath = that.staticPath + '/theme/' + themeValue + '/' + cssArray[i].toLowerCase() + '.css' console.log(itemPath)
loadCss(itemPath) }
localStorage.setItem('themeValue', themeValue)
function loadCss(path) { var head = document.getElementsByTagName('head')[0] var link = document.createElement('link') link.href = path link.rel = 'stylesheet' link.type = 'text/css' head.appendChild(link) } function removeCss(href) { const links = document.getElementsByTagName('link') const head = document.getElementsByTagName('head')[0] const arr = [] if (links && links.length > 0) { for (let i = 0, len = links.length; i < len; i++) { if (links[i]) { arr.push(links[i]) } } for (let i = 0, len = arr.length; i < len; i++) { head.removeChild(arr[i]) } } } }
}
// export default global
|