naive-ui/demo/documentation/theme/zhCN/readTheme.md
2020-02-05 13:13:48 +08:00

667 B
Raw Blame History

获取主题

使用配置消费者Config Consumer来获取当前位置上的主题。

<n-config-provider :theme="theme">
  <n-button @click="theme = 'dark'">深色</n-button>
  <n-button @click="theme = 'light'">浅色</n-button>
  <n-config-consumer
    @theme-change="handleThemeChange"
  >
    <template v-slot="{ theme }">
      <div>主题:{{ theme }}</div>
    </template>
  </n-config-consumer>
</n-config-provider>
export default {
  data () {
    return {
      theme: 'dark'
    }
  },
  methods: {
    handleThemeChange (theme) {
      this.$NMessage.info(theme)
    }
  }
}
.n-button {
  margin: 0 12px 8px 0;
}