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

新闻列表页面:

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

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

新闻详情页:

  1)首先要获取id

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

  2)拼接到url上面 

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

  完整写法:

1
2
3
4
5
6
7
8
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传过去啦

原文地址:https://www.cnblogs.com/snowhite/p/9122714.html