首页 > 开发 > Javascript > 正文

Vue实战教程之仿肯德基宅急送App

2020-02-25 00:56:50
字体:
来源:转载
供稿:网友

Vue学习有一段时间了,就想着用Vue来写个项目练练手,弄了半个月,到今天为止也算勉强能看了。

由于不知道怎么拿手机App的接口,并且KFC电脑端官网真的...一言难尽,所以项目所有数据都是我截图然后写在EasyMock里的,有需要的同学可以自取

首页 商品页 外卖页

技术栈

vue + webpack + vuex + axios

文件目录

│ App.vue│ main.js│├─assets│   logo.png│├─components│ │ cartcontrol.vue│ │ code.vue│ │ coupon.vue│ │ mineHeader.vue│ │ scroll.vue│ │ shopHeader.vue│ │ sidebar.vue│ │ submitBar.vue│ │ takeout.vue│ │ wallet.vue│ ││ └─tabs│     Other.vue│     Outward.vue│     Selfhelp.vue│     Vgold.vue│├─pages│ ├─home│ │   home.vue│ ││ ├─mine│ │   mine.vue│ ││ ├─order│ │   order.vue│ ││ └─shop│     shop.vue│├─router│   index.js│└─vuex  │ store.js  │ types.js  │  └─modules      com.js      cou.js      take.js

效果展示

定义的组件

better-scroll

因为每个页面都需要滑动,所以一开始就把scroll组件封装好,之后使用的话引入一下就行了

<template> <div ref="wrapper">  <slot></slot> </div></template><script>import BScroll from 'better-scroll';const DIRECTION_H = 'horizontal';const DIRECTION_V = 'vertical';export default { name: 'scroll', props: {  /**   * 1 滚动的时候会派发scroll事件,会节流。   * 2 滚动的时候实时派发scroll事件,不会节流。   * 3 除了实时派发scroll事件,在swipe的情况下仍然能实时派发scroll事件   */  probeType: {   type: Number,   default: 1  },  /**   * 点击列表是否派发click事件   */  click: {   type: Boolean,   default: true  },  /**   * 是否开启横向滚动   */  scrollX: {   type: Boolean,   default: false  },  /**   * 是否派发滚动事件   */  listenScroll: {   type: Boolean,   default: false  },  /**   * 列表的数据   */  data: {   type: Array,   default: null  },  pullup: {   type: Boolean,   default: false  },  pulldown: {   type: Boolean,   default: false  },  beforeScroll: {   type: Boolean,   default: false  },  /**   * 当数据更新后,刷新scroll的延时。   */  refreshDelay: {   type: Number,   default: 20  },  direction: {   type: String,   default: DIRECTION_V  } }, methods: {  _initScroll() {   if(!this.$refs.wrapper) {    return   }   this.scroll = new BScroll(this.$refs.wrapper, {    probeType: this.probeType,    click: this.click,    eventPassthrough: this.direction === DIRECTION_V ? DIRECTION_H : DIRECTION_V   })   // 是否派发滚动事件   if (this.listenScroll) {    this.scroll.on('scroll', (pos) => {     this.$emit('scroll', pos)    })   }   // 是否派发滚动到底部事件,用于上拉加载   if (this.pullup) {    this.scroll.on('scrollEnd', () => {     if (this.scroll.y <= (this.scroll.maxScrollY + 50)) {      this.$emit('scrollToEnd')     }    })   }   // 是否派发顶部下拉事件,用于下拉刷新   if (this.pulldown) {    this.scroll.on('touchend', (pos) => {     // 下拉动作     if (pos.y > 50) {      this.$emit('pulldown')     }    })   }   // 是否派发列表滚动开始的事件   if (this.beforeScroll) {    this.scroll.on('beforeScrollStart', () => {     this.$emit('beforeScroll')    })   }  },  disable() {   // 代理better-scroll的disable方法   this.scroll && this.scroll.disable()  },  enable() {   // 代理better-scroll的enable方法   this.scroll && this.scroll.enable()  },  refresh() {   // 代理better-scroll的refresh方法   this.scroll && this.scroll.refresh()  },  scrollTo() {   // 代理better-scroll的scrollTo方法   this.scroll && this.scroll.scrollTo.apply(this.scroll, arguments)  },  scrollToElement() {   // 代理better-scroll的scrollToElement方法   this.scroll && this.scroll.scrollToElement.apply(this.scroll, arguments)  }, }, mounted() {  setTimeout(() => {   this._initScroll()  },20) }, watch: {  data () {   setTimeout(() => {    this.refresh()   },this.refreshDelay)  } },}</script><style></style>            
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表