自学vue 之去哪儿网首页中recommend和weekend组件布局开发部分笔记

       今天练习的还是慕课网Dell Lee老师的Vue2.5开发去哪儿网App 从零基础入门到实战项目课程的实战篇,推荐recommend部分和周末去哪儿weekend部分组件布局开发,算是静态的布局,其中data数据部分有待优化(需要用ajax请求,目前还不是很会,如有大神请指教,谢谢啦~),效果如下:

      首先还是在线上git创建分支index-recommend和index-weekend,在拉到本地进行相应文件引入,引入如下:

      在对应 .vue文件中进行板块布局,布局如下:

   在recommend.vue代码如下:

<template>
  <div>
    <div class="title">热销推荐</div>
    <ul>
      <li class="item border-bottom" v-for="item of recommendList" :key="item.id">
        <img class="item-img" :src="item.imgUrl"/>
        <div class="item-info">
          <p class="item-title">{{item.title}}</p>
          <p class="item-desc">{{item.desc}}</p>
          <button class="item-button">查看详情</button>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'HomeRecommend',
  data () {
    return {
      recommendList: [{
        id: '0001',
        imgUrl: 'http://img1.qunarzz.com/sight/p0/1705/99/99cad7081abb9771a3.img.jpg_200x200_d86753f0.jpg',
        title: '大连圣亚海洋世界',
        desc: '浪漫大连首站,浪漫的海洋主题乐园',
        button: '查看详情'
      }, {
        id: '0002',
        imgUrl: 'http://img1.qunarzz.com/sight/p0/1705/99/99cad7081abb9771a3.img.jpg_200x200_d86753f0.jpg',
        title: '大连圣亚海洋世界',
        desc: '浪漫大连首站,浪漫的海洋主题乐园',
        button: '查看详情'
      }, {
        id: '0003',
        imgUrl: 'http://img1.qunarzz.com/sight/p0/1705/99/99cad7081abb9771a3.img.jpg_200x200_d86753f0.jpg',
        title: '大连圣亚海洋世界',
        desc: '浪漫大连首站,浪漫的海洋主题乐园',
        button: '查看详情'
      }, {
        id: '0004',
        imgUrl: 'http://img1.qunarzz.com/sight/p0/1705/99/99cad7081abb9771a3.img.jpg_200x200_d86753f0.jpg',
        title: '大连圣亚海洋世界',
        desc: '浪漫大连首站,浪漫的海洋主题乐园'
      }]
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/minins.styl'
  .title
    margin-top: .2rem
    line-height: .8rem
    background: #eee
    text-indent: .2rem
  .item
    overflow: hidden
    display: flex
    heihgt: 1.9rem
    .item-img
      width: 1.7rem
      height: 1.7rem
      padding: .16rem
    .item-info
      flex: 1
      padding: .1rem
      min-width: 0
      .item-title
        line-height: .54rem
        font-size: .32rem
        ellipsis()
      .item-desc
        line-height: .4rem
        color: #ccc
        ellipsis()
      .item-button
        line-height: .44rem
        margin-top: .16rem
        background: #ff9300
        padding: 0 .2rem
        border-radius: .06rem
        color: #fff
</style>

   在weekend.vue代码如下:

<template>
  <div>
    <div class="title">周末去哪儿</div>
    <ul>
      <li class="item border-bottom" v-for="item of recommendList" :key="item.id">
        <div class="item-img-wrapper">
          <img class="item-img" :src="item.imgUrl"/>
        </div>
        <div class="item-info">
          <p class="item-title">{{item.title}}</p>
          <p class="item-desc">{{item.desc}}</p>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'HomeWeekend',
  data () {
    return {
      recommendList: [{
        id: '0001',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1806/de/df09fa61aed2d502.jpg_750x200_67472739.jpg',
        title: '大连圣亚海洋世界',
        desc: '浪漫大连首站,浪漫的海洋主题乐园',
        button: '查看详情'
      }, {
        id: '0002',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1806/de/df09fa61aed2d502.jpg_750x200_67472739.jpg',
        title: '大连圣亚海洋世界',
        desc: '浪漫大连首站,浪漫的海洋主题乐园',
        button: '查看详情'
      }, {
        id: '0003',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1806/de/df09fa61aed2d502.jpg_750x200_67472739.jpg',
        title: '大连圣亚海洋世界',
        desc: '浪漫大连首站,浪漫的海洋主题乐园',
        button: '查看详情'
      }, {
        id: '0004',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1806/de/df09fa61aed2d502.jpg_750x200_67472739.jpg',
        title: '大连圣亚海洋世界',
        desc: '浪漫大连首站,浪漫的海洋主题乐园'
      }]
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/minins.styl'
  .title
    margin-top: .2rem
    line-height: .8rem
    background: #eee
    text-indent: .2rem
  .item-img-wrapper
    overflow: hidden
    height: 0
    padding-bottom: 26.9%
    .item-img
      width: 100%
  .item-info
    padding: .1rem
    .item-title
      line-height: .54rem
      font-size: .32rem
      ellipsis()
    .item-desc
      line-height: .4rem
      color: #ccc
      ellipsis()
</style>

      最后,笔记说明一下:

  (1) flex: 1   /* 自适应撑开,可以理解为高度等于父级高度 */
  (2) 当添加文本溢出省略时,若无效果,考虑其父级宽度是否为设定,可设为min-width:0,再查看效果
  (3) 给li的底部边框 添加1像素边框 因前面已做了样式引入,则需直接在li的class里加入border-bottom

哈哈!每次感觉博客篇幅还有蛮长的,还是记性不怎么好,仅以此笔记供日后查阅!也希望能帮助大家~

猜你喜欢

转载自blog.csdn.net/lha1995/article/details/81612856
今日推荐