Pinia之在js文件中使用store(个人笔记)

import store from "@/store";
import { useSystemStore } from "@/store/system";
const systemStore = useSystemStore(store);

export const setFontSize = (initSize?: number) => {
  //基准大小
  const baseSize = initSize || 16;
  let screenWidth;
  const mediaQueryList = window.matchMedia("(orientation: landscape)");
  if (mediaQueryList.matches) {
    // 横屏
    screenWidth = 812;
    systemStore.setLandscape(true);
  } else {
    // 竖屏
    screenWidth = 375;
    systemStore.setLandscape(false);
  }
  const scale = document.documentElement.clientWidth / screenWidth;
  //设置页面根节点字体大小, 字体大小最小为10
  let fontSize =
    baseSize * Math.min(scale, 2) > 10 ? baseSize * Math.min(scale, 2) : 10;
  return fontSize + "px";
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容