rem配置(大屏适配)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// rem等比适配配置文件
// 基准大小
const baseSize = 16;
// 设置 rem 函数
function setRem() {
// 当前页面宽度相对于 1920宽的缩放比例,可根据自己需要修改。
const scale = document.documentElement.clientWidth / 1920;
// 设置页面根节点字体大小(“Math.min(scale, 2)” 指最高放大比例为2,可根据实际业务需求调整)
document.documentElement.style.fontSize = baseSize * Math.min(scale, 2) + "px";
}
// 初始化
setRem();
// 改变窗口大小时重新设置 rem
window.onresize = function() {
setRem();
}

去掉包括空格,存储名称两端多余空格(数据处理)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export const multipleSpace = (str, needTrim = true) => {
if (typeof str === "string") {
let _str = "";
const arr = str.split(/\n/);
if (arr && arr.length) {
arr.forEach((v, i) => {
const re = v.replace(/\s+/g, " ");
_str = _str + (i !== 0 ? "\n" : "") + (needTrim ? re.trim() : re);
});
}
return _str;
} else if (typeof str === "object" && str !== null) {
const obj = {};
Object.keys(str).forEach(item => {
obj[item] = multipleSpace(str[item]);
});
return obj;
} else {
return str;
}
}

国际化处理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import Vue from "vue";
import VueI18n from "vue-i18n";
import enLocale from "./en";
import zhLocale from "./zh";
import elementEn from "element-ui/lib/locale/lang/en";
import elementZh from "element-ui/lib/locale/lang/zh-CN";
import { i18nKey } from "@/settings";
console.log(i18nKey);
Vue.use(VueI18n);

const messages = {
zh: {
...zhLocale,
...elementZh
},
en: {
...enLocale,
...elementEn
}
};
const i = window.localStorage.getItem(i18nKey);

const i18n = new VueI18n({
locale: i || "zh", // set locale
messages, // set locale messages
});

// 设置国际化语言
if (!i) window.localStorage.setItem(i18nKey, "zh");

export default i18n;
avatar
yushangyou
个人博客
Follow Me
公告
This is my Blog
最新文章
网站资讯
文章数目 :
12
本站总字数 :
6.6k
本站访客数 :
本站总访问量 :
最后更新时间 :