[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
在数组的使用中,我们通常会有数组的过滤的需求,比如值 在某个范围内的数字,用来组成一个新的数组,这就用到了数组的过滤
比如:
var number=[23,3,51,65,13,45,65,23,63] //此时想取出大于25的数字,返回一个新数组 number.filter(
item=>{ return item>25 } 此时的filter就起到了过滤的功能
在vue中应用
比如说频道管理一共是25个频道, 我的频道中已有部分频道,剩下的 点击添加更多频道中的内容则是 总共的频道-我的频道= 点击添加更多频道
此时用过滤器filter最合适不过
unCheckChannel代表过滤完的频道,也就是可以往我的频道中可以添加的频道,allChannelList代表所有的25个频道,userCheckChannel代表我的频道,具体接口数据不在此展示,我们只用数据来说话.
看vue中的代码:
findIndex会去寻找重复的频道,如果找到重复的会返回1,找不到重复的会返回-1,在此定义一个变量index,让他大于-1,其实就是找到了重复的,因为重复的数据是我们所不需要的,所以返回一个错误,剩下的让他返回正确.
至于computed是vue中的计算属性,在此用它最合适不过.