1. store/index.js中获取后台配置
export const actions = {
async nuxtServerInit({ commit }, { $api }) {
const config = $api.web.getConfig()
commit('setConfig', config)
},
}
2. layouts/default.vue中根据配置设置html的class
这里能将filter样式加在body上,会导致fixed失效,参考:详解filter与fixed冲突的原因及解决方案_小毛嗑儿的博客-优快云博客
<template>
<Nuxt></Nuxt>
</template>
<script>
export default {
head() {
return {
htmlAttrs: {
class: this.$store.state.config.gray ? 'html-gray' : '',
},
}
},
}
</script>
<style>
.html-gray {
filter: grayscale(100%);
}
</style>