YuJian
/
Storyofvue
Archived
1
0
Fork 0
Browse Source

ajax

detail-ajax
遇见 5 years ago
parent
commit
860d2f5a06
  1. 3
      src/App.vue
  2. 58
      src/pages/detail/Detail.vue
  3. 22
      src/pages/detail/components/banner.vue
  4. 23
      src/router/index.js

3
src/App.vue

@ -6,5 +6,4 @@
</div> </div>
</template> </template>
<style> <style></style>
</style>

58
src/pages/detail/Detail.vue

@ -1,6 +1,10 @@
<template> <template>
<div> <div>
<detail-banner></detail-banner> <detail-banner
:sightName="sightName"
:bannerImg="bannerImg"
:gallaryImgs="gallaryImgs"
></detail-banner>
<detail-header></detail-header> <detail-header></detail-header>
<div class="content"><detail-list :list="list"></detail-list></div> <div class="content"><detail-list :list="list"></detail-list></div>
</div> </div>
@ -10,6 +14,7 @@
import DetailBanner from "./components/banner"; import DetailBanner from "./components/banner";
import DetailHeader from "./components/header"; import DetailHeader from "./components/header";
import DetailList from "./components/list"; import DetailList from "./components/list";
import axios from "axios";
export default { export default {
name: "Detail", name: "Detail",
@ -18,36 +23,37 @@ export default {
DetailHeader: DetailHeader, DetailHeader: DetailHeader,
DetailList: DetailList DetailList: DetailList
}, },
data: function() { methods: {
return { getDetailInfo: function() {
list: [ axios
{ .get("/api/detail.json", {
title: "成人票", params: {
children: [ id: this.$route.params.id
{
title: "成人三馆联票",
children: [
{
title: "成人三馆联票 - 某一连锁店销售"
} }
] })
.then(this.getDetailDataSucc);
}, },
{ getDetailDataSucc: function(res) {
title: "成人五馆联票" res = res.data;
if (res.ret && res.data) {
const data = res.data;
this.sightName = data.sightName;
this.bannerImg = data.bannerImg;
this.gallaryImgs = data.gallaryImgs;
this.list = data.categoryList;
}
} }
]
},
{
title: "学生票"
},
{
title: "儿童票"
}, },
{ data: function() {
title: "特惠票" return {
sightName: "",
bannerImg: "",
gallaryImgs: [],
list: []
} }
] },
}; activated: function() {
this.getDetailInfo();
} }
}; };
</script> </script>

22
src/pages/detail/components/banner.vue

@ -1,20 +1,17 @@
<template> <template>
<div> <div>
<div class="banner" @click="handleBannerClick"> <div class="banner" @click="handleBannerClick">
<img <img class="banner-img" :src="bannerImg" />
class="banner-img"
src="https://img1.qunarzz.com/sight/p0/1602/a2/a2db6aea3707663a90.img.jpg_600x330_95322c03.jpg"
/>
<div class="banner-info"> <div class="banner-info">
<div class="banner-title">梦幻百花洲</div> <div class="banner-title">{{ this.sightName }}</div>
<div class="banner-number"> <div class="banner-number">
<span class="iconfont back-icon banner-icon">&#xe638;</span> <span class="iconfont back-icon banner-icon">&#xe638;</span>
39 {{ this.gallaryImgs.length }}
</div> </div>
</div> </div>
</div> </div>
<commit-gallery <commit-gallery
:imgs="imgs" :imgs="gallaryImgs"
v-show="showGallery" v-show="showGallery"
@close="handleGalleryClose" @close="handleGalleryClose"
></commit-gallery> ></commit-gallery>
@ -26,13 +23,14 @@ import CommitGallery from "commom/gallery/Gallery";
export default { export default {
name: "DetailBanner", name: "DetailBanner",
props: {
sightName: String,
bannerImg: String,
gallaryImgs: Array
},
data: function() { data: function() {
return { return {
showGallery: false, showGallery: false
imgs: [
"http://img1.qunarzz.com/sight/p0/1602/a2/a2db6aea3707663a90.img.jpg_r_800x800_f06fc71d.jpg",
"http://img1.qunarzz.com/sight/p0/1602/ec/ecf4f576181c285790.img.jpg_r_800x800_c2833cda.jpg"
]
} }
}, },
components: { components: {

23
src/router/index.js

@ -1,29 +1,30 @@
import Vue from "vue"; import Vue from "vue";
import VueRouter from "vue-router"; import Router from "vue-router";
import Home from "@/pages/home/home"; import Home from "@/pages/home/home";
import City from "@/pages/city/City"; import City from "@/pages/city/City";
import Detail from "@/pages/detail/Detail"; import Detail from "@/pages/detail/Detail";
Vue.use(VueRouter); Vue.use(Router);
const routes = [ export default new Router({
routes: [
{ {
path: "/", path: "/",
name: "Home", name: "Home",
component: Home component: Home
},{ },
{
path: "/city", path: "/city",
name: "City", name: "City",
component: City component: City
},{ },
{
path: "/detail/:id", path: "/detail/:id",
name: "Detail", name: "Detail",
component: Detail component: Detail
} }
]; ],
scrollBehavior(to, from, savedPosition) {
const router = new VueRouter({ return { x: 0, y: 0 };
routes }
}); });
export default router;