2019-12-07 00:02:31 +08:00
|
|
|
# Provide Theme
|
2020-12-12 14:44:44 +08:00
|
|
|
|
2020-03-20 22:52:54 +08:00
|
|
|
Use `n-config-provider` to set the theme of all its descedant components.
|
2019-12-07 00:02:31 +08:00
|
|
|
|
|
|
|
```html
|
2021-02-02 13:44:57 +08:00
|
|
|
<n-config-provider :theme="theme">
|
2020-05-31 13:38:35 +08:00
|
|
|
<n-card>
|
2020-11-30 14:29:48 +08:00
|
|
|
<n-space>
|
2021-01-12 17:49:39 +08:00
|
|
|
<n-button @click="theme = darkTheme">Dark</n-button>
|
2021-02-02 12:24:48 +08:00
|
|
|
<n-button @click="theme = null">Light</n-button>
|
2020-11-30 14:29:48 +08:00
|
|
|
</n-space>
|
2020-05-31 13:38:35 +08:00
|
|
|
</n-card>
|
2019-12-07 00:02:31 +08:00
|
|
|
</n-config-provider>
|
|
|
|
```
|
2020-12-12 14:44:44 +08:00
|
|
|
|
2019-12-07 00:02:31 +08:00
|
|
|
```js
|
2021-01-12 17:49:39 +08:00
|
|
|
import { ref } from 'vue'
|
2021-02-02 11:50:58 +08:00
|
|
|
import { darkTheme } from 'naive-ui'
|
2021-01-12 17:49:39 +08:00
|
|
|
|
2019-12-07 00:02:31 +08:00
|
|
|
export default {
|
2021-01-12 17:49:39 +08:00
|
|
|
setup () {
|
2019-12-07 00:02:31 +08:00
|
|
|
return {
|
2021-01-12 17:49:39 +08:00
|
|
|
darkTheme,
|
2021-02-02 12:24:48 +08:00
|
|
|
theme: ref(null)
|
2019-12-07 00:02:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|