js四个for循环遍历数组拿到数组和的方式
2021-03-02 10:28
标签:必须 逻辑 cti ota spl compute book += his js四个for循环遍历数组拿到数组和的方式 标签:必须 逻辑 cti ota spl compute book += his 原文地址:https://www.cnblogs.com/qingzuihub/p/14411342.html// 写vueJS逻辑
// @ts-ignore
const app = new Vue({
el: ‘#app‘,
data() {
return {
books: [
{
id: 1,
name: ‘《周文强牛逼1》‘,
date: ‘2021-1-1‘,
price: 88.00,
count: 1,
},
{
id: 2,
name: ‘《周文强牛逼2》‘,
date: ‘2021-2-1‘,
price: 88.00,
count: 1,
},
{
id: 3,
name: ‘《周文强牛逼3》‘,
date: ‘2021-3-1‘,
price: 88.00,
count: 1,
},
{
id: 4,
name: ‘《周文强牛逼4》‘,
date: ‘2021-4-1‘,
price: 88.00,
count: 1,
},
{
id: 5,
name: ‘《周文强牛逼5》‘,
date: ‘2021-5-1‘,
price: 88.00,
count: 1,
},
]
}
},
methods: {
add(bookIndex) {
// console.log(‘add--‘);
this.books[bookIndex].count++
},
sub(bookIndex) {
// console.log(‘sub--‘);
this.books[bookIndex].count--
},
deleteBook(bookIndex) {
this.books.splice(bookIndex, 1)
}
},
//过滤器
filters: {
showPrice(price) {
return ‘¥‘ + price.toFixed(2)
}
},
//计算属性
computed: {
totalPrice() {
// let totalPrice = 0
// 1、普通for循环
// for(let i = 0; i n n*2).reduce((preVal, n) => preVal + n)
// console.log(total);
//=============//=============//=============
//map|reduce|filter
//filter中的毁掉函数必须返回bool值
//true: 函数把n添加到数组
//false:过滤掉这个n
//=============//=============//=============
//1、filter函数使用
//需求,取出数组中小于100的数字
// let newnums = nums.filter(function(n) {
// return n
文章标题:js四个for循环遍历数组拿到数组和的方式
文章链接:http://soscw.com/index.php/essay/58993.html