笔记(不定期一直更新)

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,不使用插件

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bangbang给你两锤

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值