2020-06-18 00:25:14 +08:00
|
|
|
# Theme Environments
|
|
|
|
Sometimes you may need some component to access some values at specific theme. You can use `theme-environments`.
|
2019-11-28 16:17:21 +08:00
|
|
|
```html
|
2020-02-03 19:28:16 +08:00
|
|
|
<div>
|
|
|
|
<n-button @click="theme = 'dark'">Dark Theme</n-button>
|
|
|
|
<n-button @click="theme = 'light'">Light Theme</n-button>
|
|
|
|
</div>
|
2020-06-18 00:25:14 +08:00
|
|
|
<n-config-provider :theme="theme" :theme-environments="env">
|
2020-05-31 13:38:35 +08:00
|
|
|
<n-config-consumer v-slot="{ themeEnvironment }">
|
|
|
|
<n-card>
|
|
|
|
<n-tag>{{ themeEnvironment }}</n-tag>
|
|
|
|
</n-card>
|
2019-11-28 16:17:21 +08:00
|
|
|
</n-config-consumer>
|
|
|
|
</n-config-provider>
|
|
|
|
```
|
|
|
|
```js
|
|
|
|
export default {
|
|
|
|
data () {
|
|
|
|
return {
|
2020-05-31 13:38:35 +08:00
|
|
|
theme: 'dark',
|
2019-11-28 16:17:21 +08:00
|
|
|
env: {
|
2020-02-03 19:28:16 +08:00
|
|
|
dark: 'NaCl',
|
|
|
|
light: 'Ionic Compound'
|
2019-11-28 16:17:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-27 16:11:23 +08:00
|
|
|
```
|
|
|
|
```css
|
|
|
|
.n-button {
|
|
|
|
margin: 0 8px 12px 0;
|
|
|
|
}
|
2019-11-28 16:17:21 +08:00
|
|
|
```
|