vue列表到详情页的实现
路由里边的 router/index.jspath:'/detail/:id' 动态id
列表页渲染时: :to="'/detail/'+item.id"===>id是指请求文章列表的id,可以是aid,bid等等请求列表接口:http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=1点击进入路由变http://localhost:8080/#/detail/456详情页需要请求文章详情的接口http://www.phonegap100.com/appapi.php?a=getPortalArticle&aid=456,传入 this.$route.params.id和路由里面一样的id写死mounted(){var aid=this.$route.params.id; //console.log(aid)//调用请求数据的方法this.requestData(aid); }, methods:{requestData(aid){//get请求如果跨域的话 后台php java 里面要允许跨域请求var api='http://www.phonegap100.com/appapi.php?a=getPortalArticle&aid='+aid; this.$http.get(api).then((response)=>{ console.log(response); this.detail=response.data.result[0]; //根据数据结构赋值},(err)=>{console.log(err) }) } }
【vue列表到详情页的实现】转载于:https://www.cnblogs.com/lwj820876312/p/9107910.html
推荐阅读
- 2018-02-06第三天|2018-02-06第三天 不能再了,反思到位就差改变
- 一个小故事,我的思考。
- 第三节|第三节 快乐和幸福(12)
- 你到家了吗
- 遇到一哭二闹三打滚的孩子,怎么办┃山伯教育
- 死结。
- 赢在人生六项精进二阶Day3复盘
- 子龙老师语录
- 异地恋中,逐渐适应一个人到底意味着什么()
- vue-cli|vue-cli 3.x vue.config.js 配置