/* 碰盏日记 - 主题混入 (Theme Mixin) * 每个页面混入此mixin,自动在onShow时刷新日夜主题 * 页面根视图需绑定 :class="themeClass" */ import { getCurrentTheme, applyTheme } from './utils' export default { data() { return { themeClass: 'theme-dark', currentTheme: 'dark' } }, created() { this._refreshTheme() }, onShow() { this._refreshTheme() }, methods: { _refreshTheme() { const theme = getCurrentTheme() this.currentTheme = theme this.themeClass = theme === 'light' ? 'theme-light' : 'theme-dark' applyTheme(theme) } } }