1. js获取自己的ip地址:
<script type="application/javascript"> function getIP(json) { localStorage.setItem('localIp', json.ip) } </script> <script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script>
2. 根据ip地址查询所在城市:${ip} 是自己的ip地址
https://restapi.amap.com/v3/ip?ip=${ip}&output=json&key=ff2897e97491d3245b5ac4a867df4b77
3. 根据城市查询天气:(应该是黑马的接口,什么时候失效不知道),${city}是城市,注意不能带市
http://ajax-api.itheima.net/api/weather?city=${city}
4. 前端大屏适配缩放组件vue3-scale-box - npm
cnpm install vue3-scale-box //使用方法: <template> <ScaleBox :width="1920" :height="1080" :delay="100"> <router-view /> </ScaleBox> </template> <script> import ScaleBox from "vue3-scale-box"; </script> <style lang="scss"></style> //在***.d.ts下面 declare module 'vue3-scale-box' //摘自 https://blog.csdn.net/AdminGuan/article/details/127971358
5. 常用正则表达式
手机号码正则:/^[1][0-9]{10}$/;
固定电话正则:/^(\d{3}-\d{8})$|^(\d{4}-\d{7})$/;
邮箱正则:/^\w+([-+.]\w+)*@\w+([.]\w+)*$/
身份证正则:/^\d{15}$|^\d{17}[x|X]$|^\d{18}&/;此处为简单正则校验,对身份证进行复杂校验后续更新;
中文姓名正则:/^[\u4e00-\u9fa5]{1,20}(·[\u4e00-\u9fa5]{1,20})*$/;包含对新疆地区中文姓名校验;
6.防抖:在事件被触发n秒后再执行回调,如果在这n秒内又被触发,则重新计时
export const debounce = (() => { let timer = null return (callback, wait = 800) => { timer&&clearTimeout(timer) timer = setTimeout(callback, wait) } })() //使用 debounce(() => { console.log('加载数据') }, 500) }
7.节流
export const throttle = (() => { let last = 0 return (callback, wait = 800) => { let now = +new Date() if (now - last > wait) { callback() last = now } } })()
8.前端下载excel,不使用插件