
ES6
冷太阳a
小小前端工程师,小本本记笔记。
展开
-
js数组常用方法
find() 方法返回数组中满足提供的测试函数的原创 2022-09-23 15:19:06 · 215 阅读 · 0 评论 -
js八股文心得体会
function ADD(x = 1, y = 0) { this.x = x this.y = y}ADD.prototype.addFn = function() { return this.x + this.y}const m = new ADD(5, 6) // console.log(m); // console.log(m.addFn()); // // 普通函数、 // function fnP(a, b, c) { /原创 2022-02-26 22:38:36 · 645 阅读 · 0 评论 -
vue-router中页面直接拿参数的 props传值的三种方式
一、原始方法{path: ‘/about/:id/:name’,component: About}页面拿参数 : this.$route.params.id二、props(布尔值方法)tips:此方法只能通过params方式上行得通{path: ‘/about/:id/:name’,component: About,props:true}页面拿参数 在页面 props:['id','name]二、props(函数方法) { path: '/about/:id原创 2022-02-14 14:40:37 · 1130 阅读 · 0 评论 -
js获取本月初与月底的时间、获取前一天的时间。
可以在utils.js里面封装通用方法,引入即可使用。/* 获取本月初跟月底*/export const getCurrentMonth = () => { // 2021-10-01 00:00:00 let firstDate = new Date(); let startDate = firstDate.getFullYear() + "-" + (firstDate.getMonth() + 1 < 10 ? "0" : "") + (.原创 2021-11-02 15:01:42 · 725 阅读 · 0 评论 -
js中 数组根据某个字段去重
1.封装过滤数据的方法 unique(arr, val) { const res = new Map() return arr.filter((item) => !res.has(item[val]) && res.set(item[val], 1)) },2.直接调用去重方法 this.newData=this.unique(this.obj, "schoolName") // newData 一个新的数组来接受 方法中传需要去重的数组和原创 2021-01-07 16:10:40 · 4573 阅读 · 2 评论 -
函数式编程之高阶函数用法
this.resArr = this.arr.filter(n => n % 2 == 0).map(n => n * 2).reduce((pre, n) => pre + n)原创 2020-09-15 21:38:54 · 255 阅读 · 0 评论 -
详解ES6 let块级作用域
ECMAScript 6 中let对声明变量有了严格要求,与其es6之前的var有以下区别不存在变量提升先来解释一下 var变量提升代码`console.log(a);var a=“abc”`浏览器会按以下变量提升来编译代码 :1.var a //首先会找代码中是否有var(变量提升)或者function(函数提升),有的话直接将其提前后代码会按从上到下的顺序执行2. console.log(a)3.a="abc //将abc赋值给a所以以上代码输出结果为 //undefined原创 2020-05-12 15:03:35 · 742 阅读 · 0 评论 -
ES6 最简单的数组去重 Set
ES6中 set 数据结构set ES6中的set类似一个数组,但是其中的值都是唯一的,Set本身是一个构造函数,用来生成 Set 数据结构创建一个类似于数组的set 然后用es6的解构赋值转化成数组const s=new Set();s.add(1).add(2).add(3).add(2).add(1)//添加数据用add()方法,此方法是可以写成链式的let arr=[...s]输出结果:[1,2,3]//里面成员是唯一的利用里面成员是唯一来对数组去重(只能对数组里面的数字去重,不原创 2020-05-12 15:46:30 · 158 阅读 · 0 评论