2020-01-08 01:58:39 +08:00
|
|
|
# 主题环境
|
2020-02-03 19:37:56 +08:00
|
|
|
获得当前主题环境值。
|
2020-01-08 01:58:39 +08:00
|
|
|
```html
|
|
|
|
<n-button @click="theme = 'dark'">深色主题</n-button>
|
|
|
|
<n-button @click="theme = 'light'">浅色主题</n-button>
|
|
|
|
<n-config-provider :theme="theme" :theme-environment="env">
|
|
|
|
<n-config-consumer>
|
|
|
|
<template v-slot="{ themeEnvironment }">
|
2020-03-01 19:17:53 +08:00
|
|
|
<div style="background-color: rgba(128, 128, 128); padding: 8px;">
|
|
|
|
<n-tag>{{ themeEnvironment }}</n-tag>
|
|
|
|
</div>
|
2020-01-08 01:58:39 +08:00
|
|
|
</template>
|
|
|
|
</n-config-consumer>
|
|
|
|
</n-config-provider>
|
|
|
|
```
|
|
|
|
```js
|
|
|
|
export default {
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
theme: 'light',
|
|
|
|
env: {
|
2020-02-03 19:37:56 +08:00
|
|
|
dark: '氯化钠',
|
|
|
|
light: '离子化合物'
|
2020-01-08 01:58:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2020-02-03 19:37:56 +08:00
|
|
|
```css
|
|
|
|
.n-button {
|
|
|
|
margin: 0 8px 12px 0;
|
|
|
|
}
|
|
|
|
```
|