一、异步路由

  1. export default new Router({
  2. mode:"hash",
  3. routes:[
  4. ...
  5. {
  6. path:"/detail",
  7. name:"detail",
  8. /* 异步路由 */
  9. component:()=>import('@/pages/Detail')
  10. }
  11. ]
  12. })

二、get 传值

2-1 在列表页传值this.$router.push()

  1. <div @click="handleClick(data.id)"></div>
  2. export default {
  3. name:"Item",
  4. props:{
  5. data:{
  6. type:Object,
  7. required:true
  8. }
  9. },
  10. methods:{
  11. handleClick(id){
  12. console.log(id)
  13. this.$router.push(`/detail?id=${id}`)
  14. }
  15. }
  16. };

2-2 在详情页接收值this.$route.query

  1. export default {
  2. name:"Detail",
  3. computed:{
  4. id(){
  5. return this.$route.query.id
  6. }
  7. }
  8. };

2-3在详情页接收id发送http请求

  1. mounted() {
  2. this.axios.get(`/candy/detail?id=${this.id}`).then(res => {
  3. this.sub = res.data;
  4. });
  5. }

2-3 在详情页跳转回列表页

  1. this.$router.back()