2019-11-28 16:17:21 +08:00
|
|
|
# Theme Environment
|
2020-02-03 19:28:16 +08:00
|
|
|
Sometimes you may need some component to access some values at specific theme. You can use `theme-environment`.
|
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>
|
2019-11-28 16:17:21 +08:00
|
|
|
<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>
|
2019-11-28 16:17:21 +08:00
|
|
|
</template>
|
|
|
|
</n-config-consumer>
|
|
|
|
</n-config-provider>
|
|
|
|
```
|
|
|
|
```js
|
|
|
|
export default {
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
theme: 'light',
|
|
|
|
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
|
|
|
```
|