【问题标题】:Switch between Light/Dark modes according to time in Nuxt.js with Vuetify使用 Vuetify 在 Nuxt.js 中根据时间在亮/暗模式之间切换
【发布时间】:2020-06-08 01:38:41
【问题描述】:

我在nuxt.config.js vuetify 设置中默认设置了一个深色主题,它通过dark: false 激活。如何在夜间自动激活它?

【问题讨论】:

  • 写一点js看看什么时候不是晚上?

标签: vuetify.js nuxt.js


【解决方案1】:

我终于这样解决了:

  mounted() {
    this.setTheme()
  },
  methods: {
    setTheme() {
      const today = new Date()
      today.getHours() < 8 || today.getHours() > 20
        ? (this.$vuetify.theme.isDark = true)
        : (this.$vuetify.theme.isDark = false)
    }
  }

【讨论】:

    猜你喜欢
    • 2020-08-24
    • 2021-09-12
    • 1970-01-01
    • 2020-04-19
    • 2021-05-30
    • 2020-09-12
    • 2021-03-05
    • 2020-06-05
    • 2021-09-08
    相关资源
    最近更新 更多