vue2.0's computed calculates the cumulative value of the list loop
This time I will bring you vue2.0 computed to calculate the cumulative value of the list loop. What are the precautions for vue2.0 computed to calculate the cumulative value of the list loop. The following is a practical case. Let’s take a look. one time.
The example is as follows:
<template> <p class="hello"> <h1>{{ msg }}</h1> <h2>Foo</h2> <p v-for ="(item, index) in list"> <!--<p>{{item }}</p>--> <h1 v-show="false">{{a[index] = item.bb}}</h1> <!-- <h1>index:{{index}}</h1>--> </p> <h2>a:{{a}}</h2> <h2>{{cc}}</h2> <!--<button v-on:click="cc">点击</button>--> </p> </template> <script> export default { name: 'foo', data () { return { msg: '这儿是Foo', list:[{ insertId: 'asfasf252', bb:29 },{ insertId: '2652', bb:20 },{ insertId: '996', bb:18 }], a:[] } }, computed:{ cc: function(){ var sum = 0; for(var i= 0 ;i< this.a.length; i++) { sum += parseInt(this.a[i]); } return sum; } } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> h1, h2 { font-weight: normal; } ul { list-style-type: none; padding: 0; } li { display: inline-block; margin: 0 10px; } a { color: #42b983; } </style>
How to modify the value in vue request data
How to assign $set to an array in vue.js renew
The above is the detailed content of vue2.0's computed calculates the cumulative value of the list loop. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



List operation //Insert a value from the head of the list. $ret=$redis->lPush('city','guangzhou');//Insert a value from the end of the list. $ret=$redis->rPush('city','guangzhou');//Get the elements in the specified range of the list. 0 represents the first element of the list, -1 represents the last element, and -2 represents the penultimate element. $ret=$redis->l

1: JSONArray to ListJSONArray string to List//Initialize JSONArrayJSONArrayarray=newJSONArray();array.add(0,"a");array.add(1,"b");array.add(2,"c") ;Listlist=JSONObject.parseArray(array.toJSONString(),String.class);System.out.println(list.to

Vue error: The computed attribute cannot be used correctly for data calculation. How to solve it? When developing with Vue, the computed attribute is a very commonly used and powerful feature, which can help us calculate and process data. But sometimes we encounter some problems, such as being unable to use the computed attribute correctly for data calculation. At this time we need to solve this problem. Here is a simple example to illustrate this problem:<template>&

Vue component communication: using watch and computed for data monitoring Vue.js is a popular JavaScript framework, and its core idea is componentization. In a Vue application, data needs to be transferred and communicated between different components. In this article, we will introduce how to use Vue's watch and computed to monitor and respond to data. watch In Vue, watch is an option, which can be used to monitor the changes of one or more properties.

Method to convert list to numpy: 1. Use the numpy.array() function. The first parameter of the function is a list object, which can be a one-dimensional or multi-dimensional list; 2. Use the numpy.asarray() function, which will try its best to Use the data type of the input list; 3. Use the numpy.reshape() function to convert the one-dimensional list into a multi-dimensional NumPy array; 4. Use the numpy.fromiter() function, the first parameter of the function is an iterable object.

Example In this example, we first look at the usage of list.sort() before continuing. Here, we have created a list and sorted it in ascending order using sort() method - #CreatingaListmyList=["Jacob","Harry","Mark","Anthony"]#DisplayingtheListprint("List=",myList)#SorttheListsinAscendingOrdermyList .sort(

How to sort a list using the List.Sort function in C# In the C# programming language, we often need to sort the list. The Sort function of the List class is a powerful tool designed for this purpose. This article will introduce how to use the List.Sort function in C# to sort a list, and provide specific code examples to help readers better understand and apply this function. The List.Sort function is a member function of the List class, used to sort elements in the list. This function receives

1. The most common way (not necessarily the best) is through Arrays.asList(strArray). After converting the array into List, you cannot add or delete the List, you can only check and modify it, otherwise an exception will be thrown. Key code: Listlist=Arrays.asList(strArray);privatevoidtestArrayCastToListError(){String[]strArray=newString[2];Listlist=Arrays.asList(strArray);//Insert a piece of data into the converted list list.add(" 1"
