vue-router之nuxt动态路由设置的方法

方法一:router-link

class="slide-item" v-for="user in shareData.users"> :to="'/community/member/'+ user.id"> src="../../static/head.png" alt="">

{{user.nickname}}

注意:1---to前面别忘记加一个冒号,作为动态路径,用变量理解

           2--正常路由别忘记带引号(本身是字符串)

方法二:函数式路由

1.在listItem设置一个函数go(id),准备跳转到详情页

class="mov-container" v-for="item in shareData.moments" >
class="mov-item" >
class="mov-img" v-for="photo in item.moment.medias" @click="go(item.moment.id)"> :src="photo" alt=""> src="../../assets/image/player.png" alt="" class="player">
class="mov-con">{{item.moment.content}}
class="mov-data">
class="mov-data-l">:src="item.user.avatar" alt="">{{item.user.nickname}}
class="mov-data-r" :class="{bg1:chose1,bg2:chose2}" @click="changeBg">{{item.moment.like}}

2.路径中加个参数即可

go(id) {
    this.$router.push({
        path: '/comments/' + id,
    });
}

你可能感兴趣的:(vue-router之nuxt动态路由设置的方法)