判断是否为设备来源
const isMobile = ()=>{return /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i.test(navigator.userAgent)}
- 服务端如何判断
- 发起请求的时候,会带上请求头:User-Agent
preg_match_all("/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i",$_SERVER['HTTP_USER_AGENT']);
移动端适配rem
const htmlDom = document.querySelector("html");
const handleWindowResize = () => {
const scale = document.documentElement.clientWidth / 10;
htmlDom.style.fontSize = scale + "px";
};
handleWindowResize();
window.addEventListener("resize", handleWindowResize);
获取url中的query
function getQuery(str = "") {
if (str[0] === "?") {
str = str.substring(1);
}
let list: string[] = [];
let obj: any = {};
list = str.split("&");
list.forEach((item) => {
let index = item.indexOf("=");
obj[item.substring(0, index)] = item.substring(index + 1, item.length);
});
return obj;
}
``