vue 列表页跳转详情页获取id以及详情页通过id获取数据
更新时间:2019年03月27日 14:48:42 作者:荔枝吖
这篇文章主要介绍了vue 列表页跳转详情页获取id以及详情页通过id获取数据,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
1.先在router.js中配置路由
{ path: '/movieDetail/:movieId', name: 'movieDetail', component:movieDetail }
2.获取详情页的id,并派发父组件事件(movieList.vue)页面
<li v-for="(item,index) in movies" :key="index" @click="selectItem(item)"> 。。。。。。。 </li>
methods:{ selectItem(item){ //console.log(item.moveId); //var item = item.moveId; this.$emit('select',item); }
3.在movieShow页面引用movieList.vue页面
<movieList :movies="movies" @select="movieDetail"></movieList>
//转入电影详情页 movieDetail(item){ console.log(`${item.moveId}`); this.$router.push({ path: `/movieDetail/${item.moveId}` }) }
效果如下:
上面获取到了 id,接下来实现详情页通过id获取数据
1)先获取传过来的id
var movieId = that.$route.params && that.$route.params.movieId;
2)引用豆瓣网的API
/v2/movie/subject/:id
单个电影条目信息
const url = `api/movie/subject/${movieId}`; that.$axios.get(url) .then((res)=>{ console.log(res.data); })
效果如下
3)在页面中引用
<scroll class="movie-detail" :data="movieDetail" > 。。。。。。 </scroll>
在js中将movieDetail进行赋值 movieDetail = res.data
data(){ return { movieDetail:{} } }, created(){ this._getDateil(); }, components:{ scroll }, methods:{ _getDateil(){ var that = this; var movieId = that.$route.params && that.$route.params.movieId; console.log(movieId); //that.getMovieDetail(movieId); const url = `api/movie/subject/${movieId}`; that.$axios.get(url) .then((res)=>{ console.log(res.data); movieDetail = res.data; }) },
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
为vue中的data赋值computed计算属性后,出现undefined原因及解决
这篇文章主要介绍了为vue中的data赋值computed计算属性后,出现undefined原因及解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2023-07-07Vue通过getAction的finally来最大程度避免影响主数据呈现问题
这篇文章主要介绍了Vue通过getAction的finally来最大程度避免影响主数据呈现,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2020-04-04
最新评论