【发布时间】:2018-04-02 13:36:39
【问题描述】:
这是我从 url 获得的数据。我只需要打印第 2 行和第 4 行,
{
"status": "ok",
"source": "n",
"sortBy": "top",
"articles": [
{
"author": "Bradford ",
"title": "friends.",
"url": "http: //",
"urlToImage": "http://"
},
{
"author": "Bradford ",
"title": "Kershaw threw six mesmerizing innings to put L.A. into the Fall Classic.",
"url": "http: //",
"urlToImage": "http://"
},
"author": "Bord ",
"title": "Kershaw threw six mesmerizing innings to put L.A. into the Fall Classic.",
"url": "http: //",
"urlToImage": "http://"
},
"author": "Brad ",
"title": "Kershaw threw six mesmerizing innings to put L.A. into the Fall Classic.",
"url": "http: //",
"urlToImage": "http://"
}
]
}
我的 vue js 脚本如下。这就是我从相应的 url 检索值的方式
<script>
new Vue({
el: '#feed' ,
data: {
articles: [],
},
mounted() {
this.$nextTick(function() {
var self = this;
$.ajax({
url: "https://newsapi.org/v1/articles?source=espn&sortBy=top&apiKey=4db9d5d381a14ffcbca8e8a9aa8b864c",
method: "GET",
dataType: "JSON",
success: function (e) {
if (e.status == 'ok') {
self.articles = e.articles;
console.log(e.articles)
}
}, error: function(){
console.log('Error occurred');
}
});
})
},
})
</script>
我的 HTML 是
<div id="feed">
<div v-for="post in articles" class="mke_">
<div class="row">
{{post.title}}
</div>
</div>
</div>
请帮我只显示第 2 篇和第 4 篇文章[]? 我在js方面很弱。所以,能帮到我就好了
【问题讨论】:
-
如何确定需要第 2 行和第 4 行?
标签: javascript html vue.js vuejs2 vue-component