我从未见过这么美妙的项目,当然与我接触的项目少有关,但是这个项目满满的艺术气息,让人沉醉,让人忍不住的去研究代码。
先放项目地址:https://github.com/eidonlon/imitate-beautiful-thing
再来看一下项目的效果

接下来我们来研究代码吧~
我们先来看项目的入口文件main.js
main.js作为入口引入App.vue

<template><div id="app"><router-view></router-view></div>
</template><script>
export default {name: 'App'
};
</script>

我们来分析main.js里面的内容,逐条分析
关于引入的路由

import Vue from 'vue'
import Router from 'vue-router'
// 这种也好玩,引入组件,再在router中注册
import pageView from '@/pages/pageView'
import Home from '@/pages/home'
import Things from '@/pages/things'
import Designer from '@/pages/designer'
import Personal from '@/pages/personal'
import Pictoral from '@/pages/pictoral'
import Details from '@/pages/details'
import Comment from '@/pages/comment'
import About from '@/pages/about'Router.prototype.goBack = function(){this.isBack = true;window.history.go(-1);
};Vue.use(Router);const routers = new Router({routes: [{path:'',name:'',component:pageView,children:[{path:'/',name:'',component:Home,children:[{path:'',name:'pictoral',meta:{index:1},component:Pictoral},{path:'/things',name:'things',meta:{index:1},component:Things},{path:'/designer',name:'designer',meta:{index:1},component:Designer},{path:'/personal',name:'personal',meta:{index:1},component:Personal},]},{path:'/details/:id',name:'details',meta:{index:2},component:Details},{path:'/comment/:id',name:'comment',meta:{index:2},component:Comment},{path:'/about',name:'about',meta:{index:2},component:About}]}]
})routers.beforeEach(function (to, from, next) { document.body.scrollTop = document.documentElement.scrollTop = 0// 进入下一个页面的时候,都是页面的top为0那种next()
});export default routers;

我们会发现引入了vue-scroller,这个其实是实现下拉刷新,上拉获取数据的功能的。
store中的内容不多,只是对tabIndex做了一个简单的下标赋值

//index.js
import Vue from 'vue'
import Vuex from 'vuex'Vue.use(Vuex)const store = new Vuex.Store({state:{tabIndex:0},mutations:{changeTab: function(state,index){state.tabIndex = index;}}
});export default store

在mian.js页面还引入了tabBar,swiper,toast组件
先看tabBar组件

<template><div class="tab-bar"><ul><li v-for="(item,index) in itemList" :key="index" class="tab-bar-item" :class="{active: index == isActive}" @click="addActive(index,item)"><span class="tab-bar-item_icon" :class="item.icon"></span><span class="tab-bar-item_Text">{{item.text}}</span></li></ul></div>
</template>
<script>export default{name:'tabbar',data (){return {isActive:this.$store.state.tabIndex,itemList:[{text:"推荐",icon:"fa fa-clipboard",link:'/'},{text:"作品",icon:"fa fa-smile-o",link:'/things'},{text:"设计师",icon:"fa fa-pencil",link:'/designer'},{text:"我",icon:"fa fa-user-o",link:'/personal'}]}},mounted(){if(this.isActive != 0){this.$router.push(this.itemList[this.isActive].link);}},methods:{addActive: function(index,item){console.log('.....index',index)console.log('...item',item.link)this.isActive = index;this.$router.push(item.link);this.$store.commit("changeTab",index);}}};
</script>
//swiper.vue
<template><div class="swiper-box"><swiper :options="swiperOption" ref="swiper" ><swiper-slide v-for="(data, index) in dataList" :key="index":class="{active: activeIndex == index}"><slot name="swiperMain" :data="data">{{data.text}}</slot>   </swiper-slide><div class="swiper-pagination" slot="pagination"></div></swiper></div>
</template>
<script>import 'swiper/dist/css/swiper.css'import { swiper, swiperSlide} from 'vue-awesome-swiper'export default{name: 'appnav',props:{activeIndex:{},swiperOption:{type:Object},dataList:{}},components:{swiper,swiperSlide}};
</script>
//toast.vue
<template><transition name="toast-fade"><div class="toast" v-show="visible" ><div class="toast-content">{{message}}</div></div></transition>
</template>
<script>
export default {name:'toast',data(){return {visible:false,message:''}}
}
</script>
//main.js
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
import store from './store'
import scroller from 'vue-scroller'
import 'font-awesome/scss/font-awesome.scss'
import './assets/style/reset.css'
import './assets/style/style.scss'
import tabbar from './components/tabBar'
import swiper from './components/swiper'
import toast from './components/toast'Vue.config.productionTip = false
Vue.config.devtools = trueVue.prototype.$axios = axios;Vue.use(scroller)
Vue.use(tabbar)
Vue.use(swiper)
Vue.use(toast)new Vue({router,store,components: { App },render: h => h(App),
}).$mount("#app");

接下来我们结合router来看页面

//src\pages\pageView.vue
<template><div class="page-view"><transition :name="transitionName"><router-view class="child-view"></router-view></transition></div>
</template>
<script>export default {name:"pageView",data() {return {transitionName:'slide-left'}},watch:{$route: function(to,from){console.log('what is to',to)console.log('what is from',from)let isBack = this.$router.isBack;if(isBack){this.transitionName = 'slide-right';}else{this.transitionName = 'slide-left';}this.$router.isBack = false;},}}/*  */
</script>
//src\pages\pageView.vue
<template><div class="tab-bar"><ul><li v-for="(item,index) in itemList" :key="index" class="tab-bar-item" :class="{active: index == isActive}" @click="addActive(index,item)"><span class="tab-bar-item_icon" :class="item.icon"></span><span class="tab-bar-item_Text">{{item.text}}</span></li></ul></div>
</template>
<script>export default{name:'tabbar',data (){return {isActive:this.$store.state.tabIndex,itemList:[{text:"推荐",icon:"fa fa-clipboard",link:'/'},{text:"作品",icon:"fa fa-smile-o",link:'/things'},{text:"设计师",icon:"fa fa-pencil",link:'/designer'},{text:"我",icon:"fa fa-user-o",link:'/personal'}]}},mounted(){if(this.isActive != 0){this.$router.push(this.itemList[this.isActive].link);}},methods:{addActive: function(index,item){console.log('.....index',index)console.log('...item',item.link)this.isActive = index;this.$router.push(item.link);this.$store.commit("changeTab",index);}}};
</script>

效果为

代码为:

<template><div class="personal"><div class="personal-logo"><div class="logo"><span class="logo_img"><img src="/static/images/logo.jpg" alt=""></span><span>登录</span></div></div><div class="personal-main"><div class="personal-main_menu"><ul><li><i class="fa fa-thumbs-o-up"></i><span>我推荐的</span></li><li><i class="fa fa-heart-o"></i><span>我关注的</span></li><li><i class="fa fa-folder-open-o"></i><span>我的作品</span></li></ul></div><div class="personal-main_list"><ul><li><i class="fa fa-bell-o"></i><span>消息中心</span><i class="fa fa-angle-right"></i></li><li><i class="fa fa-bullhorn"></i><span>联系我</span><i class="fa fa-angle-right"></i></li><li @click="toAbout"><i class="fa fa-meh-o"></i><span>关于</span><i class="fa fa-angle-right"></i></li></ul></div></div></div>
</template>
<script>import {prevent} from '../utils'export default{name: 'personal',mounted(){document.body.removeEventListener("touchmove",prevent);},methods: {toAbout:function(){this.$router.push("/about");}}};
</script>

//src\pages\about.vue
<template><div class="about"><div class="page-title">    <span @click="goBack" class="goBack"><i class="fa fa-2x fa-angle-left"></i></span>  <h3>关于</h3> </div><div class="main"><p>声明:这只是一个练习的demo :( </p></div></div>
</template>
<script>export default{name: '',data (){return{desc:''}},methods: {goBack: function(){ this.$router.goBack();  }}};
</script>

//src\pages\things.vue
<template><div class="things"><div class="things-nav"><swiper :dataList="navList" :activeIndex="activeIndex" ref="navSwiper" :swiperOption="swiperOptionNav" ></swiper></div><div class="things-main"><scroller :on-refresh="refresh" :refreshText="refreshText" ref="scroller"><span style="width:20px;height:20px;" class="spinner" slot="refresh-spinner"></span><div class="things-time">TODAY</div><swiper :dataList="navList"  :swiperOption="swiperOptionMain"  ref="mainSwiper"><div slot="swiperMain" slot-scope="slotProps"><div v-for="(item, index) in slotProps.data.dataList" :key="index" class="things-item" ><div class="things-img-wrapper" @click="showDetails(item.id)"><img class="things-item_img" :src="item.img" alt=""><span class="things-item_tips">{{item.author}}</span></div><div class="things-item-foot"><div class="foot-desc"><span class="foot-desc_logo"><img :src="item.icon" alt=""></span><div class="foot-desc_text"><p>{{item.author}}</p><p class="origin">{{item.origin}}</p></div></div><div class="foot-action"><span @click="like(item)" class="fa fa-meh-o action-up"></span><span  v-show="item.likeNum" class="like">+<i>{{item.likeNum}}</i></span> | <span @click="dislike(item)" class="fa fa-frown-o action-down"></span><span v-show="item.dislikeNum" class="dislike"><i>{{item.dislikeNum}}</i></span></div></div></div></div></swiper></scroller><div class="to-top" @click="toTop"><i class="fa fa-arrow-up"></i></div></div></div>
</template>
<script>import { mixin,pageAct } from '../utils'export default{name: 'things',data (){return{likeNum:0,dislikeNum:0,}},mixins:[mixin,pageAct],methods:{showDetails: function(index){this.$router.push("/comment/"+index);},getData: function(cb){var self = this;this.$axios.post("/things",{}).then(function(response){console.log('aaaaa...',response)var result = response.data;if(result.code == 200){self.navList  = result.list;}}).catch(function(error){console.log(error);});},loadMore: function(cb){var self = this;this.$axios.post("/things",{author:self.activeIndex}).then(function(response){var result = response.data;cb && cb(result);}).catch(function(error){console.log(error);});}}};
</script>

//src\pages\designer.vue<template><div class="designer"><div class="designer-nav"><swiper :dataList="navList" :activeIndex="activeIndex" ref="navSwiper" :swiperOption="swiperOptionNav" ></swiper></div><div class="designer-main"><keep-alive><scroller :on-refresh="refresh" :refreshText="refreshText" ref="scroller"><span style="width:20px;height:20px;" class="spinner" slot="refresh-spinner"></span><div class="designer-time">TODAY</div><swiper :dataList="navList"  ref="mainSwiper" :swiperOption="swiperOptionMain"><div slot="swiperMain" slot-scope="slotProps"><div v-for="(item, index) in slotProps.data.dataList" :key="index" class="designer-item" ><div class="designer-img-wrapper" @click="showDetails(item.id)"><img class="designer-item_img" :src="item.img" alt=""><span class="foot-desc_logo"><img :src="item.icon" alt=""></span></div><div class="designer-item-foot"><div class="foot-desc"><div class="foot-desc_text"><p>{{item.author}} | <span class="origin">{{item.origin}}</span></p></div></div><div class="foot-action"><span @click="showTotast" class="foot-actionr_follow">+ 关注</span></div></div></div></div></swiper></scroller></keep-alive><div class="to-top" @click="toTop"><i class="fa fa-arrow-up"></i></div></div></div>
</template>
<script>import {pageAct} from '../utils'export default{name: 'designer',mixins:[pageAct],methods:{showDetails: function(index){this.$router.push("/details/"+index);},getData: function(cb){var self = this;this.$axios.post("/designer",{}).then(function(response){console.log('designer',response)var result = response.data;if(result.code == 200){self.navList  = result.list;}}).catch(function(error){console.log(error);});},loadMore: function(cb){var self = this;this.$axios.post("/designer",{author:self.activeIndex}).then(function(response){var result = response.data;cb && cb(result);}).catch(function(error){console.log(error);});},showTotast: function(){this.$toast({message:"敬请期待关注功能 :-)"});}}};
</script>


```vue
//src\pages\details.vue


<span @click="goBack" class="goBack">

{{title}}


<img :src="img" alt="">
简介

<div class="desc-item" v-for="(item, index) in descList" :key="index">
<i class="fa" :class="item.icon">

{{item.tips}}:

{{item.text}}

其他作品

<div class="desc-img-item" v-for="(item, index) in imgList" :key="index">

—{{item.originate}}—
<img :src="item.img" alt="">

—— 没有了呢 ——

转载于:https://www.cnblogs.com/smart-girl/p/11160453.html

【vue】imitate-beautiful-thing相关推荐

  1. 【vue】使用localStorage解决vuex在页面刷新后数据被清除的问题

    [vue]使用localStorage解决vuex在页面刷新后数据被清除的问题 参考文章: (1)[vue]使用localStorage解决vuex在页面刷新后数据被清除的问题 (2)https:// ...

  2. 【Vue】Vue中的父子组件通讯以及使用sync同步父子组件数据

    前言: 之前写过一篇文章<在不同场景下Vue组件间的数据交流>,但现在来看,其中关于"父子组件通信"的介绍仍有诸多缺漏或者不当之处, 正好这几天学习了关于用sync修饰 ...

  3. 【Vue】样式穿透 ::v-deep的具体使用

    [Vue]样式穿透 ::v-deep的具体使用 之前在项目中用到了 vant,使用特别简单,而且组建也非常的丰富.即时这样,在项目中肯定也需要用额外的样式来打造自己的应用. 直接在 中编写的话只会影响 ...

  4. 【Vue】npm run serve 和 npm run dev 有什么区别

    [Vue]npm run serve 和 npm run dev 有什么区别 Q: 我的粉丝私信我,项目中运行的npm run serve 和 npm run dev 有什么区别?什么时候用npm r ...

  5. 【Vue】—生命周期函数

    [Vue]-生命周期函数(钩子函数) beforeCreate 创建前(初始化事件,生命周期函数) created 创建完成(初始化注入和校验) beforeMount 渲染前(把页面编译成虚拟DOM ...

  6. 【Vue】—处理边界情况

    [Vue]-处理边界情况 一.边界处理-$ref vue是数据驱动的 很少直接操作dom元素,但是有的时候的确需要操作dom 这是vue中提供ref来获取dom <div ref='myref' ...

  7. 【Vue】—异步组件

    [Vue]-异步组件 一. 组件引入方式:提前引入 import CompA from './components/CompA.vue'components:{CompA} 二. 异步引入 compo ...

  8. 【Vue】—动态组件

    [Vue]-动态组件 <template><div><div>这里使用动态组件包装</div><!-- 能显示不同的组件 --><di ...

  9. 【Vue】—解决页面图片加载抖动的问题

    [Vue]-解决页面图片加载抖动的问题 问题如下 解决办法 overflow:hidden; height:0; padding-bottom:*; // 其中*处填 图片的高宽百分比=高/宽*100 ...

  10. 【Vue】—解构插槽 Prop以及具名插槽的缩写

    [Vue]-解构插槽 Prop以及具名插槽的缩写

最新文章

  1. mysql 中文截取_mysql 截取中文字符
  2. D - Silver Cow Party POJ - 3268
  3. 科技互联网公司越来越重视数学了,贾扬清等大牛如是说!
  4. PHP项目学习——控件
  5. 信令风暴问题根因分析
  6. java 对增删该查进行测试_java连接mysql增删改查测试通过
  7. Java:使用DOM4j来实现读写XML文件中的属性和元素
  8. 压缩版styleGAN(Mobile StyleGAN)参数更少、计算复杂度更低
  9. 紫光展锐【软件工程师】面经
  10. iis6 无法访问网站_IIS重启无效
  11. DeepID1 分析
  12. 杭电acm 4282 A very hard mathematic problem
  13. ug如何复制面_了解了一下内容,让你UG快速入门
  14. 上云十年:阿里云的奇幻漂流
  15. WinEdit 的algorithm2e包自定义一个带竖线的模块代码
  16. Chapter5.1:频率响应法
  17. C# 实现像QQ一样隐藏窗体
  18. 联接无止境!500万台AP潜在大数据流量入口
  19. 服务器能进系统滴滴响,主机报警连续响个不停
  20. 2023届秋招提前批信息汇总(持续更新ing)

热门文章

  1. liunx安装xfs包挂载大于16T的硬盘
  2. 计算机安装固态硬盘后启动不稳定,完美解决win7系统安装固态硬盘后开机慢的解决方法...
  3. 用java做一个校园网站,基于jsp的校园网站-JavaEE实现校园网站 - java项目源码
  4. linux系统怎么拨号上网,linux配置上网 linux adsl拨号上网设置
  5. 【短道速滑四】Halcon的texture_laws算子自我研究
  6. hdu 5064 Find Sequence(单调性优化DP)
  7. 彻底搞懂git代码冲突问题----产生冲突以及解决冲突
  8. LiveNas: Neural-Enhanced Live Streaming: Improving Live Video Ingest via Online Learning解读
  9. HTTP Live Streaming
  10. IcedTea:首个100%兼容、开源的Java