YuJian
/
Storyofvue
Archived
1
0
Fork 0
Browse Source

ajax

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

3
src/App.vue

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

2
src/commom/gallery/Gallery.vue

@ -19,7 +19,7 @@ export default {
type: Array, type: Array,
default: function() { default: function() {
return []; return [];
} }
} }
}, },
data: function() { data: function() {

64
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
}, },
methods: {
getDetailInfo: function() {
axios
.get("/api/detail.json", {
params: {
id: this.$route.params.id
}
})
.then(this.getDetailDataSucc);
},
getDetailDataSucc: function(res) {
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;
}
}
},
data: function() { data: function() {
return { return {
list: [ sightName: "",
{ bannerImg: "",
title: "成人票", gallaryImgs: [],
children: [ list: []
{ }
title: "成人三馆联票", },
children: [ activated: function() {
{ this.getDetailInfo();
title: "成人三馆联票 - 某一连锁店销售"
}
]
},
{
title: "成人五馆联票"
}
]
},
{
title: "学生票"
},
{
title: "儿童票"
},
{
title: "特惠票"
}
]
};
} }
}; };
</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: {

43
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: "/", {
name: "Home", path: "/",
component: Home name: "Home",
},{ component: Home
path: "/city", },
name: "City", {
component: City path: "/city",
},{ name: "City",
path: "/detail/:id", component: City
name: "Detail", },
component: Detail {
path: "/detail/:id",
name: "Detail",
component: Detail
}
],
scrollBehavior(to, from, savedPosition) {
return { x: 0, y: 0 };
} }
];
const router = new VueRouter({
routes
}); });
export default router;