vue2.0 computed 計算list循環(huán)后累加值的實例
更新時間:2018年03月07日 14:51:52 作者:huang100qi
下面小編就為大家分享一篇vue2.0 computed 計算list循環(huán)后累加值的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
實例如下所示:
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<h2>Foo</h2>
<div v-for ="(item, index) in list">
<!--<p>{{item }}</p>-->
<h1 v-show="false">{{a[index] = item.bb}}</h1>
<!-- <h1>index:{{index}}</h1>-->
</div>
<h2>a:{{a}}</h2>
<h2>{{cc}}</h2>
<!--<button v-on:click="cc">點擊</button>-->
</div>
</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>
以上這篇vue2.0 computed 計算list循環(huán)后累加值的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Vue.js每天必學之計算屬性computed與$watch
- Vue computed計算屬性的使用方法
- vue 解決computed修改data數(shù)據(jù)的問題
- Vue的watch和computed方法的使用及區(qū)別介紹
- Vue中computed與methods的區(qū)別詳解
- Vue 2.0學習筆記之Vue中的computed屬性
- vue計算屬性computed的使用方法示例
- 詳解vue中的computed的this指向問題
- Vue——解決報錯 Computed property "****" was assigned to but it has no setter.
- Vue.js中的computed工作原理
- 詳解vue中computed 和 watch的異同
- Vue.js第三天學習筆記(計算屬性computed)
- 淺談vue的props,data,computed變化對組件更新的影響
- Vue中計算屬性computed的示例解讀
- vue.js的computed,filter,get,set的用法及區(qū)別詳解
- vue計算屬性computed、事件、監(jiān)聽器watch的使用講解
- Vue 中 filter 與 computed 的區(qū)別與用法解析
- vue中計算屬性computed理解說明包括vue偵聽器,緩存與computed的區(qū)別
相關(guān)文章
vue el-table實現(xiàn)多選框回填的示例代碼
摘要:Vue多選框回填是實現(xiàn)表單數(shù)據(jù)高效處理的常見需求,本文主要介紹了vue el-table實現(xiàn)多選框回填的示例代碼,具有一定的參考價值,感興趣的可以了解一下2024-01-01
Vue?先初始化父組件再初始化子組件的方法(自定義父子組件mounted執(zhí)行順序)
這篇文章主要介紹了Vue?先初始化父組件再初始化子組件的方法(自定義父子組件mounted執(zhí)行順序),本篇內(nèi)容內(nèi)容主要講述了,在使用?Konva?進行開發(fā)過程中遇到的一些問題,需要的朋友可以參考下2024-07-07
vue使用v-for循環(huán)獲取數(shù)組最后一項
這篇文章主要介紹了vue使用v-for循環(huán)獲取數(shù)組最后一項問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03

