![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
es6
lixiaonaaa
写bug的
展开
-
外卖软件评星功能
评星功能直接上代码starClasses () { const {score} = this //分数,例如4.7 const scs = [] // 向scs中添加n个CLASS_ON const scoreInteger = Math.floor(score) for (let i = 0; i < scoreInteger; i++) { scs.push(CLASS_ON)原创 2021-01-30 18:07:14 · 146 阅读 · 0 评论 -
js 将一维数组转化为二维数组
/* 根据categorys一维数组生成一个2维数组 小数组中的元素个数最大是8 */ categorysArr () { const {categorys} = this // 准备空的2维数组 const arr = [] // 准备一个小数组(最大长度为8) let minArr = [] // 遍历categorys categorys.forEach(c => { // 如果当前小.原创 2021-01-29 23:44:57 · 1012 阅读 · 1 评论 -
js find(),findIndex()方法的使用
1, find()方法用于查找数组中符合条件的第一个元素,如果没有符合条件的元素,则返回undefinedlet arr = [1,2,3,4,5];let num = arr.find(item => item > 1);console.log(num)输出: 22, findeIndex()方法用于找到数组中第一个符合条件的元素的下标,如果所有成员都不符合条件,则返回-1let arr = [1,2,3,4,5];let num = arr.findIndex(it原创 2021-01-16 18:41:19 · 4922 阅读 · 2 评论 -
es6 箭头函数的this指向问题
先看两段代码://普通函数function foo() { setTimeout(function(){ console.log('id:', this.id); }, 100);}var id = 21;foo.call({ id: 42 });//输出 id: 21//箭头函数function foo() { setTimeout(() => { console.log('id:', this.id); }, 100);原创 2021-01-20 10:18:29 · 199 阅读 · 0 评论