vue-router 动态导航 router-link :to属性

经常碰到这类需求,从后台获取数据后再前程连接,参数id动态获取

            <el-row v-for="item in Travels">
              <el-col :span="24">
                <el-card :body-style="{ padding: '0px' , width : '100%'}">
                  <router-link :to="{path:'/travel/detail/'+ item.id}"><img :src="item.img" class="image"></router-link>
                  <div style="padding: 14px;">
                    <span class="description">{{item.description}}</span>
                    <div class="bottom clearfix">
                      <time class="time">{{item.time}}</time>
                    </div>
                  </div>
                </el-card>
              </el-col>
            </el-row>
        </div>
:to="{path:'/travel/detail/'+ item.id}" 利用:to 属性可以动态分配

        mounted(){
            this.GetTravel(this.$route.params.days);
        }

使用 

this.$route.params.days 可以获取当前路由参数
{{$route.params.id}} 可以在模板中获取当前路由参数
 
原文地址:https://www.cnblogs.com/xiaoliwang/p/8365613.html