ref.ts 774 B

1234567891011121314151617181920212223242526272829303132
  1. import { Ref, ref } from 'vue';
  2. const browserBlack = () => {
  3. return (
  4. window.matchMedia &&
  5. window.matchMedia('(prefers-color-scheme: dark)').matches
  6. );
  7. };
  8. export class RefData {
  9. private static instance: RefData;
  10. public static getInstance(): RefData {
  11. if (this.instance == null) {
  12. this.instance = new RefData();
  13. let localTheme = localStorage.getItem('nutui-theme-color');
  14. if (localTheme) {
  15. this.instance.themeColor.value = localTheme;
  16. }
  17. }
  18. return this.instance;
  19. }
  20. public currentRoute: Ref<string> = ref('/');
  21. private _themeColor: Ref<string> = ref('black');
  22. public get themeColor(): Ref<string> {
  23. return this._themeColor;
  24. }
  25. public set themeColor(v: Ref<string>) {
  26. this._themeColor = v;
  27. }
  28. }