Vue通過id跳轉到商品詳情頁


方法一:通過

<router-link :to="">我要跳轉,別攔我</router-link>



首頁列表:

在這里我用a標簽進行跳轉,在vue里面使用<router-link></router-link>

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

 

 商品詳情頁:

 

//請求接口
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); }); }

 

方法二:通過綁定點擊事件跳轉頁面(比較常用,純手寫,有啥問題,歡迎加群討論!)

 1 <ul>
 2    <li v-for="(item,index) in items" :key="index" @click="jumpPage(item.id)">我要跳轉誰也別攔我</li>
 3 </ul>
 4 
 5 data(){
 6     return:{
 7         items:[
 8         {
 9            id:1
10          },
11         {
12            id:2
13          },
14         {
15            id:3
16          }
17       ]
18    }
19 },
20   methods: {
21    jumpPage(id) {
22       this.$router.push({
23         path: '路由地址',
24         query: {
25           id: id
26         }
27       })
28     },
29 }     

 

 

若有不明白請加群號:復制 695182980 ,也可掃碼,希望能幫助到大家。

                                      

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM