【发布时间】:2018-05-01 16:53:24
【问题描述】:
我想用 vueJS 从我的 json 中计算数据
数据是这样的
来自我的 api 的 json
[
{
"id": 4,
"votes": 0
},
{
"id": 3,
"votes": 1
},
]
为了获取和渲染这些数据,我使用了这个 vueJS 文件
app.js
const vm = new Vue({
el: '#app',
data: {
results: []
},
mounted() {
axios.get("http://example.com/votes.json")
.then(response => {this.results = response.data})
},
});
现在我想创建一个 vue 变量来显示我的 index.html 中的总票数
index.html
<div v-for="result in results">
<p>Votes {{ result.votes }}.</p>
<p>Id : {{ result.id }}</p>
</div>
<div>
<p>Total of votes : {{ resultsVotes }}</p>
</div>
【问题讨论】:
-
问题是……?如何计算
resultsVotes? -
我想“我想用 vueJS 从我的 json 计算数据”和“现在我想创建一个 vue 变量来显示我的 index.html 中的总票数”非常简单......
标签: javascript json vue.js