1.全局过滤器

(1)normalTime.js  自定义 将 时间戳 转换成 日期格式 过滤器

/*** 将 时间戳 转换成 日期格式*/
export const normalTime = (time) => {if(time){var oDate = new Date();oDate.setTime(time);var y = oDate.getFullYear();var m = oDate.getMonth() + 1;var d = oDate.getDate();var h = oDate.getHours();var mm = oDate.getMinutes();var s = oDate.getSeconds();return y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s;}
}

(2)index.js  入口文件

/*** 过滤器* 入口文件*/
import { normalTime } from './normalTime'// webpack 2中不允许混用import和module.exports
// module.exports = {
//  normalTime
// };export default {normalTime
};

2.全局引入

main.js

import Vue from 'vue'
import App from './App.vue'
// 引入 路由
import VueRouter from 'vue-router'
// 引入 路由配置文件
import routes from './router.config'
// 引入 vuex入口文件
import store from './store/index'
// 引入 axios
import axios from 'axios'
// 引入 loading 组件
import Loading from './components/loading'
// 全局引入 自定义过滤器
import filters from './filters'// 向过滤器里添加函数// ES6 循环遍历所有过滤器
Object.keys(filters).forEach(key => Vue.filter(key, filters[key]))/*** 以前* Vue.filter(名字,函数);* 例如:Vue.filter('filtername',function(value,参数){return 参数+value.split('').reverse().join('');});*/
/*Vue.filter('normalTime',(time) => {if(time){var oDate = new Date();oDate.setTime(time);var y = oDate.getFullYear();var m = oDate.getMonth() + 1;var d = oDate.getDate();var h = oDate.getHours();var mm = oDate.getMinutes();var s = oDate.getSeconds();return y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s;}
});*/Vue.use(VueRouter);
Vue.use(Loading);// 关于axios配置
axios.interceptors.request.use(function(config){// 发送请求store.dispatch('showLoading');return config;
},function(error){return Promise.reject(error);
});axios.interceptors.response.use(function(response){// 请求回来store.dispatch('hideLoading');return response;
},function(error){return Promise.reject(error);
});// 配置请求的根路径
// axios.default.baseURL = 'http://localhost:8080';// 设置默认头部信息 post
// axios.default.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';// 把axios对象挂到Vue原型上
Vue.prototype.$http = axios;// 创建 路由
const router = new VueRouter({mode:'history', // 删除 url 中的'#'号,切换路径模式scrollBehavior:() => ({y:0}), // 滚动条滚动的行为,不加这个默认就会记忆原来滚动条的位置routes // routes 等价于 routes:routes
});require('./assets/css/base.css'); // 全局引入new Vue({el: '#app',router,store,render: h => h(App)
})

3.在组件中使用

Article.vue

4.动画效果 (transition 实现动画效果)

App.vue

<template><div id="app"><loading v-show="loading"></loading><NavView v-show="headerShow"></NavView><!-- transition 实现动画效果 --><transition name="slide-down"><!-- keep-alive 如果有数据,则保持原样 --><!-- <keep-alive><router-view class="router-view"></router-view></keep-alive> --><router-view class="router-view"></router-view></transition><FooterView></FooterView></div>
</template><script>
/*** 引入 组件*/
// 头部导航
import NavView from './components/Nav.vue'
// 底部选项卡
import FooterView from './components/Footer.vue'// 引入 vuex 的两个方法
import {mapGetters, mapActions} from 'vuex'export default {// 计算属性computed:mapGetters([// 从getters中获取headerShow的值'headerShow','loading']),watch:{ // 监听,当路由发生变化的时候执行$route(to,from){if(to.path == '/user-info'){/*** $store来自Store对象* dispatch 向 actions 发起请求*/this.$store.dispatch('hideHeader');}else{this.$store.dispatch('showHeader');}}},components:{NavView,FooterView}
}
</script><style lang="scss">@import './assets/css/index.css';.slide-down-enter-active,.slide-down-leave-active{transition: .4s all ease;opacity:0.2;transform:translate3d(0,6em,0);}.slide-down-enter,.slide-down-leave{opacity:1;transform:translate3d(0,6em,0);}
</style>

5.效果图

转载于:https://www.cnblogs.com/crazycode2/p/7598508.html

vue2.0 仿手机新闻站(七)过滤器、动画效果相关推荐

  1. vue 仿二手交易app_项目vue2.0仿外卖APP(七)

    ratings评价列表页实现 在ratings.vue组件里开发 首先先引入seller数据: 书写模板结构: 由于评价页又有之前写过的star.vue组件,所以又要在ratings.vue组件引入: ...

  2. Vue2.0 仿滴滴出行项目

    Vue2.0 仿滴滴出行项目 最近,各大社区出现很多小伙伴的vue项目,趁着这股热潮我也用vue撸了一个滴滴出行的项目. 效果预览 在线预览:demo 项目地址:github 主要技术栈 vue2.0 ...

  3. 饿了吗app都是用html写的,Vue2.0仿饿了么webapp单页面应用详细步骤

    这篇文章主要为大家详细介绍了Vue2.0仿饿了么webapp单页面应用详细步骤,具有一定的参考价值,可以用来参考一下. 感兴趣的小伙伴,下面一起跟随512笔记的小编两巴掌来看看吧! 部分截图 [图片暂 ...

  4. [vue] vue2.0不再支持v-html中使用过滤器了怎么办?

    [vue] vue2.0不再支持v-html中使用过滤器了怎么办? 在method中定义方法 htmlFilter(htmlString){ return htmlString.replace(/+s ...

  5. android 自定义园动画,Android 自定View实现仿QQ运动步数圆弧及动画效果

    在之前的Android超精准计步器开发-Dylan计步中的首页用到了一个自定义控件,和QQ运动的界面有点类似,还有动画效果,下面就来讲一下这个View是如何绘制的. 1.先看效果图 2.效果图分析 功 ...

  6. vue移动端过渡动画_Vue仿微信app页面跳转动画效果

    10:14:11独立开发者在开发移动端产品时,为了更高效,通常会使用Web技术来开发移动端项目,可以同时适配Android.iOS.H5,稍加改动还可适配微信小程序. 在使用Vue.js开发移动端页面 ...

  7. android菊花动画,Android实现仿iOS菊花加载圈动画效果

    常见的实现方式 切图,做旋转动画 自定义View,绘制效果 gif图 1.切图会增加体积,但相对简单,不过在换肤的场景下,会使用不同颜色,需要准备多张图,不够灵活. 2.由于自定义的好处,不同颜色只需 ...

  8. 项目vue2.0仿外卖APP(五)

    header组件 vue-resourse应用 https://github.com/pagekit/vue-resource vue-resource是Vue.js的一款插件,它可以通过XMLHtt ...

  9. vue2.0仿饿了么webAPP项目

    # webapp vue2.x仿饿了么app项目总结 项目地址:https://github.com/harrietjia/vue2-webapp.git 如果觉得有帮助,希望可以在右上角给我个sta ...

最新文章

  1. asp.net模糊查询存储过程
  2. Java实现文件的RSA和DES加密算法
  3. pycharm Enable Live Templates的作用
  4. 计算机在生命科学中的发展前景,往生命科学领域发展的职业前景
  5. 『设计模式』工厂方法模式
  6. 10.热空气扭曲效果
  7. java并发synchronized 锁的膨胀过程(锁的升级过程)深入剖析(1)
  8. c语言指针生成numpy数组,python – 在cython中声明numpy数组和c指针
  9. 编程中的Eric常用的编程单词的缩写
  10. linux zookeeper开机启动
  11. 智能指针的标准之争:Boost vs. Loki
  12. jmeter-性能测试-学习笔记1
  13. Location定位程序驱动合集
  14. org.hibernate.TransientObjectException:The given object has a null identifier
  15. 电脑备份,电脑怎么备份系统?电脑备份系统的方法
  16. 博士申请 | 西交利物浦大学黄开竹教授组招收机器学习全奖博士生
  17. Azure基础:什么是云计算(2) NIST云计算模型定义
  18. 这10款数据可视化软件工具免费好用
  19. 网页视频之MP4文件解析
  20. Python爬虫之Selenium

热门文章

  1. 洛谷P1246C语言,codevs1246 丑数
  2. python如何实现办公自动化培训_基于python实现自动化办公学习笔记(CSV、word、Excel、PPT)...
  3. 路飞学院python官网-路飞学院-Python爬虫实战密训班-第1章
  4. 阅读王概凯老师架构漫谈系列总结
  5. 软件开发---全套规范
  6. python中对列表浅复制深复制另类的理解方式
  7. Fragment滑动切换简单案例
  8. atan与atan2的区别
  9. 用驴子拖宝马——怎样滥用结构体
  10. c# winform 程序打包部署