html:
<ul class="listul" id="articles" v-cloak>
<li v-for="(item,index) in articles">
<a href="#" @click="showArticle(index)" class="ccsl"><em>•</em>{{item.title}}</a>
<span>{{item.createtime}}</span>
<div class="clear"></div>
<div class="sub" v-html="item.description"></div>
</li>
</ul>
js代码:
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
var app = new Vue({
el:"#articles",
data:{
articles:[
],
},
mounted: function () {
var that = this;
// 为给定 ID 的 user 创建请求
axios.get('article/getAllArticleById', {
params: {
articlecategory1id: 4,
articlecategory2id: 17
}
}).then(function (response) {
console.log(response.data);
that.articles = response.data;
}).catch(function (error) {
console.log(error);
});
},
methods:{
showArticle:function(index){
console.log(index);
console.log(this.articles[index].id);
var route="42";
window.location.href="detail4.html?id="+this.articles[index].id+"&route="+route;
}
}
})
</script>