vue项目实战

该博客详细介绍了使用Vue.js进行项目实战的过程,包括实现顶部悬停效果、创建电话本列表(右侧字母分类,滑动高亮)的步骤,如依赖安装、模拟数据处理、组件编写等。此外,还讲解了如何利用Vue做代理解决跨域问题,以及实现Vue路由切换时的左滑和右滑过渡动画,涉及CSS、JS和组件交互的实践应用。
摘要由CSDN通过智能技术生成

1.顶部悬停效果

html代码

<template>
  <div class="fixtop2">

    <header class="header" ref="header"></header>

    <div class="nav" ref="nav" :class="{isFixed:isFixed}">
      <div class="box" v-for="(item,index) in list" :key="index">
        {
  {item.title}}
      </div>
    </div>

    <ul class="content">
      <li v-for="(item,index) in new Array(50)" :key="index">{
  {index+1}}</li>
    </ul>

  </div>
</template>

script代码

<script>
var throttle = require('lodash/throttle'); //从lodash中引入的throttle节流函数
(记得安装lodash :npm install lodash )
export default {
   
  name: 'navScroll2',
  data() {
   
    return {
   
      list: [
        {
    title: 'AAAA', id: 1 },
        {
    title: 'BBBB', id: 2 },
        {
    title: 'CCCC', id: 3 },
        {
    title: 'DDDD', id: 4 },
      ],
      isFixed: false, //是否固定的
      throttleScroll: null, //定义一个截流函数的变量
    };
  },
  methods: {
   
    //滚动的函数
    handleScroll() {
   
      let h = $(this.$refs.header).outerHeight(); //header的高度
      let wh = $(window).scrollTop(); //滚动的距离的,为什么这里使用的jq,因为不用考虑的什么的兼容问题
(记得引进jq)
      let navH = $(this.$refs.nav).outerHeight(); //nav的高度

      if (wh > h) {
   
        this.isFixed = true;
      } else {
   
        this.isFixed = false;
      }
    },
  },

  mounted() {
   
    //写在掉接口的里面的
    this.$nextTick(() => {
   
      //这里使用监听的scroll的事件,为什么要使用的节流函数,如果不使用的,页面一直在滚动计算的,这样在
      //使用手机时候,出现非常卡的,隔一段时间计算,大大降低了性能的消耗(具体的好处自己去查资料)
      window.addEventListener('scroll', this.throttleScroll, false);
    });

    this.throttleScroll = throttle(this.handleScroll, 100);
  },
  deactivated() {
   
    //离开页面需要remove这个监听器,不然还是卡到爆。
    window.removeEventListener('scroll', this.throttleScroll);
  },
};
</script>

style

<style scoped lang="stylus" rel="stylesheet/stylus">
.fixtop2 {
   
  min-height: 100vh;
}

.header {
   
  height: 5rem;
  width: 100%;
  background-color: red;
}

.nav {
   
  display: flex;
  width: 100%;
  background-color: pink;
  &.isFixed {
   
    position: fixed;
    left: 0;
    top: 0;
    z-index: 9999;
  }
  .box {
   
    font-size: 0.3rem;
    height: 0.9rem;
    line-height: 0.9rem;
    color: #333333;
    flex: 1;
  }
}

.content {
   
  height: 20rem;
  li {
   
    width: 100%;
    height: 1rem;
    border-bottom: 1px solid #000;
  }
}
</style>

2.电话本列表效果( 右边字母分类 上下滑动 旁边字母显示高亮)

img

1.安装依赖

"dependencies": {
   

    "better-scroll": "^0.1.15",
    
    "fastclick": "^1.0.6",
    
    "jsonp": "0.2.1",
    
    "vue": "^2.5.2",
    
    "vue-resource": "^1.5.1",
    
    "vue-router": "^3.0.1"
    
},

2.模拟数据

在根目录下写data.jon

{
   
	"errno": 0,
	"data": [
		{
   
			"Findex": "Z",
			"Fsinger_mid": "static/img/timg.jpg",
			"Fsinger_name": "张三",
			"Fsinger_tag": "541,555",
			"Fsort": "1",
			"Ftrend": "0",
			"Ftype": "0",
			"voc": "0"
		}, {
   
			"Findex": "Z",
			"Fsinger_mid": "static/img/timg.jpg",
			"Fsinger_name": "张三",
			"Fsinger_tag": "541,555",
			"Fsort": "2",
			"Ftrend": "0",
			"Ftype": "0",
			"voc": 
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值