20.进入商品详情页Detail

like.vue组件中

给li添加一个点击事件

  @click="goDetail"

对应的方法

methods:{
     goDetail(){
       this.$router.push({
         path:'/detail'
       })
     }
  },

对应home页面:添加click:true

 this.$nextTick(() => {
        this.oBetterScroll = new BetterScorll(this.$refs.wrapper, {
          movable: true,
          zoom: true,
          click: true,
        });
      });

Detail.vue编辑

<template>
  <div class="detail">
    <header>
      <div class="header-returns" v-show="isShow">
        <div><i class="iconfont icon-RectangleCopy"></i></div>
        <div>
          <i class="iconfont icon-fanhui"></i>
        </div>
      </div>
      <div class="header-bar" v-show="!isShow" :style="styleOption">
        <div><i class="iconfont icon-RectangleCopy"></i></div>
        <div>
          <span>商品详情</span>
          <span>商品评价</span>
        </div>
        <div>
          <i class="iconfont icon-fanhui"></i>
        </div>
      </div>
    </header>
    <section ref="wrapper">
      <div>
        <div class="swiper-main">
          <swiper :options="swiperOption">
            <!-- slides -->
            <swiper-slide v-for="(item, index) in detailList" :key="index">
              <img :src="item.imgUrl" alt="" />
            </swiper-slide>

            <!-- Optional controls -->
            <div class="swiper-pagination" slot="pagination"></div>
          </swiper>
        </div>
        <div class="goods-name">
          <h1>2021春花-白花 白花1号100g</h1>
          <div>性价首先,就是好喝</div>
        </div>
        <div class="goods-price">
          <div class="oprice">
            <span>$</span>
            <b>2888</b>
          </div>
          <div class="pprice">
            <span>价格:</span>
            <del>$139</del>
          </div>
        </div>
        <div>
          <img src="../assets/images/0013989_0.jpeg" alt="" />
          <img src="../assets/images/0013989_0.jpeg" alt="" />
          <img src="../assets/images/0013989_0.jpeg" alt="" />
          <img src="../assets/images/0013989_0.jpeg" alt="" />
        </div>
      </div>
    </section>
    <footer>
      <div class="left">
        <ul>
          <li>
            <i class="iconfont icon-RectangleCopy"></i>
            <span>客服</span>
          </li>
          <li>
            <i class="iconfont icon-RectangleCopy"></i>
            <span>购物车</span>
          </li>
          <li>
            <i class="iconfont icon-RectangleCopy"></i>
            <span>收藏</span>
          </li>
        </ul>
      </div>
      <div class="right">
        <div class="add-cart">加入购物车</div>
        <div>立即购买</div>
      </div>
    </footer>
  </div>
</template>

<script>
//引入better-scroll
import BetterScorll from "better-scroll";
export default {
  data() {
    return {
      detailList: [
        { id: 1, imgUrl: "./images/l1.png" },
        { id: 2, imgUrl: "./images/l11.jpeg" },
        { id: 3, imgUrl: "./images/l111.jpeg" },
      ],
      isShow: true,
      styleOption: [],
      BetterScroll: [],
      swiperOption: {
        pagination: {
          el: ".swiper-pagination",
          type: "fraction",
        },
      },
      // swiperList: [
      //   { id: 1, imgUrl: "./images/1.jpeg" },
      //   { id: 2, imgUrl: "./images/2.jpeg" },
      //   { id: 3, imgUrl: "./images/3.jpeg" },
      // ],
    };
  },
  mounted() {
    // 当dom都加载完毕了再去执行

    this.BetterScroll = new BetterScorll(this.$refs.wrapper, {
      click: true,
      //去年下拉回弹效果
      probeType: 3,
      bounce: false,
    });
    //添加滑动事件
    this.BetterScroll.on("scroll", (pos) => {
      let posY = Math.abs(pos.y);
      //下拉慢慢变透明
      let opacity = posY / 180;
      opacity = opacity > 1 ? 1 : opacity;
      this.styleOption = {
        opacity: opacity,
      };
      if (posY >= 100) {
        this.isShow = false;
      } else {
        this.isShow = true;
      }
    });
  },
};
</script>

<style scoped lang="less">
.detail {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}
section {
  flex: 1;
  overflow: hidden;
}
header {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;
  width: 100%;
  height: 1.17333rem;
  .header-returns {
    display: flex;
    width: 100%;
    height: 1.1733rem;
    justify-content: space-between;
    div {
      width: 0.9333rem;
      height: 0.9333rem;
      line-height: 0.7333rem;
      margin: 0 0.2666rem;
      border-radius: 50%;
      text-align: center;

      background-color: rgba(0, 0, 0, 0.3);
      i {
        font-size: 0.6133rem;

        color: green;
      }
    }
  }
  .header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    height: 1.1733rem;
    font-size: 0.6667rem;
    background-color: #fff;
    span {
      padding: 0 0.36666rem;
    }
    i {
      padding: 0 0.5333rem;
      font-size: 0.48666rem;
    }
  }
}
.swiper-container {
  width: 100%;
}
.swiper-main img {
  width: 100%;
}
.swiper-pagination {
  width: 100%;

  color: #666;
  font-size: 0.52666rem;
  background-origin: 0.533rem;
}

.swiper-pagination-fraction,
.swiper-pagination-custom,
.swiper-container-horizontal > .swiper-pagination-bullets {
  bottom: 0.2667rem;
  left: 4.08rem;
  width: 100%;
}
.goods-name {
  padding: 0.5333rem 0;
  border-bottom: 1px solid #999;
  h1 {
    font-size: 0.58rem;
    font-weight: 500;
  }
  div {
    padding: 0.08rem 0;
    font-size: 0.3733rem;
    color: #9999;
  }
}
.goods-price {
  padding: 0.5333rem 0.26666rem;
  .oprice {
    color: red;
    span {
      font-size: 0.32rem;
    }
  }
  .pprice {
    color: #9999;
    font-size: 0.37rem;
  }
}
footer {
  position: fixed;
  bottom: 0;
  right: 0;
  background-color: #fff;
  width: 100%;
  height: 1.3333rem;
  z-index: 999;
  display: flex;
  .left {
    display: flex;
    width: 40%;
    line-height: 1.3333rem;
    justify-content: space-around;
    ul {
      display: flex;
      line-height: 1.3333rem;
      justify-content: space-around;
      align-items: center;
      width: 100%;
      height: 100%;
      li {
        display: flex;

        flex-direction: column;
        justify-content: center;
        align-items: center;

        i {
          width: 0.7667rem;
          height: 0.7667rem;
        }
        span {
          font-size: 0.48rem;
          color: #666;
        }
      }
    }
  }
  .right {
    display: flex;
    justify-content: space-between;
    align-items: center;
    line-height: 1.3333rem;
    width: 60%;
    .add-cart {
      font-size: 0.48rem;
      text-align: center;
      color: #fff;
      width: 100%;
      height: 100%;
      background-color: #ff9500;
    }
    div {
      font-size: 0.48rem;
      text-align: center;
      color: #fff;
      width: 100%;
      height: 100%;
      background: #dd2727;
    }
  }
}
</style>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值