快速获取时间戳
+new Date() // Date.now()
axios实例二次配置
const instance = axios.create({
baseURL: 'https://some-domain.com/api/',
timeout: 1000,
headers: {'X-Custom-Header': 'foobar'}
});
- 新传入的配置将与实例的配置合并
- 官网用法 instance.request(config) 发请求
- 实际测试发现 instance(config) 和上面效果一样
- axios的拦截器可以声明多个,都能用,请求拦截器:后添加的先执行,响应拦截器:后添加的后执行
switch case的替代方案
- switch本质上两个作用:1.匹配 2.匹配不到时给默认值,基于这两点可以简化代码如下
- 尤其是case情况多的时候,这种写法比switch case要短很多
const mapVal={
test:'http://test.baidu.com',
pre:'http://pre.baidu.com'
}
finalVal = testVal in mapVal?mapVal[testVal]:'http://www.baidu.com'
善于用正则的捕获组
'http://dev.baidu.com/gqq/?code=JSynfueD4d5WBCy6sADMGQXYk&state=STATE#/home'.replace(/(.*?)\/\?(.*)#(.*)/,"$1/#$3?$2")
'http://dev.baidu.com/gqq/#/home?code=JSynfueD4d5WBCy6sADMGQXYk&state=STATE'
vconsole的替代方案
- h5调试时,如果在没有控制台的环境,还可以引入eruda
<script src="//cdn.bootcss.com/eruda/1.5.2/eruda.min.js"></script>
<script>window.eruda.init()</script>
- vue-vconsole-devtools //vue移动端调试工具
z-index
- absolute、fixed、relative定位的兄弟元素,若设置的有z-index,则层级关系依靠z-index来确定
- 不要想当然认为fixed一定在absolute前面。relative的元素也可以在fixed的前面
js filter方法
- items.value = items.value.filter((item) => item.message.match(/Foo/))
- string.match(Reg) //匹配到了返回伪数组,匹配不到返回null
- reg.test(string)