VUE通过id从列表页跳转到相对的详情页

新闻列表页面:

  在这里我用a标签进行跳转,在vue里面可以这样写<router-link></router-link> 

<router-link :to="{path:'/news',query:{ id:item.NewsID }}" class="around"></router-link>

 

新闻详情页:

  1)首先要获取id

var newsID=this.$route.query.id;

 

  2)拼接到url上面 

this.$http.get(this.$store.state.index.ip + '/api/News/'+newsID)

 

  完整写法:

created: function() {
    var newsID=this.$route.query.id;
    this.$http.get(this.$store.state.index.ip + '/api/News/'+newsID).then((response) => {
        console.log(response);
    }).catch(function(error) {
        console.log(error);
    });
}

  这样就可以把id传过去啦

 

posted @ 2017-11-20 16:32  额爷  阅读(19581)  评论(0编辑  收藏  举报