naive-ui/demo/documentation/components/config-provider/zhCN/theme-environment.demo.md

34 lines
725 B
Markdown
Raw Normal View History

2020-01-04 17:32:23 +08:00
# 主题环境
2020-02-03 19:28:16 +08:00
你有的时候可能需要让一些组件在特定主题下获取一些值,这个时候你可以设定环境主题。
2020-01-04 17:32:23 +08:00
```html
2020-02-03 19:28:16 +08:00
<div>
<n-button @click="theme = 'dark'">深色主题</n-button>
<n-button @click="theme = 'light'">浅色主题</n-button>
</div>
<n-config-provider :theme="theme" :theme-environments="env">
<n-config-consumer v-slot="{ themeEnvironment }">
<n-card>
<n-tag>{{ themeEnvironment }}</n-tag>
</n-card>
2020-01-04 17:32:23 +08:00
</n-config-consumer>
</n-config-provider>
```
```js
export default {
data () {
return {
theme: 'dark',
2020-01-04 17:32:23 +08:00
env: {
2020-02-03 19:28:16 +08:00
dark: '氯化钠',
light: '离子化合物'
2020-01-04 17:32:23 +08:00
}
}
}
}
```
2020-02-03 19:28:16 +08:00
```css
.n-button {
margin: 0 8px 12px 0;
}
```