better插件

来源:5-1 scroll-nav 组件应用

前端是我菜

2019-10-29

二期中的goods组件:
按照视频里敲出来,点击左侧右侧会滑动,但是标题不会撞击;
滑动右侧的左侧没反应,我对照源码发现也没配置什么属性,有的我全写了,但还是啥反应都没;
还有样式中,如果.goods下div我的不设置高度,goods内容就不会出来,设置得话有不太合理; 这点搞了半天,很头疼;
还请老师把这几个问题帮我解决下,要不后面就没法继续了~~

代码:

<template>
  <div class="goods">
    <div class="scroll-nav-wrapper">
      <cube-scroll-nav
        :side="true"
        :data="goods"
        :options="scrollOptions"
        :current="current"
        @change="changeHandler"
        @sticky-change="stickyChangeHandler"
      >
        <cube-scroll-nav-panel
          v-for="item in goods"
          :key="item.name"
          :label="item.name"
          :title="item.name"
        >
          <ul>
            <li v-for="(food,index) in item.foods" :key="index" class="food-item">
              <div class="icon">
                <img width="57" height="57" :src="food.icon" />
              </div>
              <div class="content">
                <h2 class="name">{{food.name}}</h2>
                <p class="desc">{{food.description}}</p>
                <div class="extra">
                  <span class="count">月售{{food.sellCount}}份</span>
                  <span>好评率{{food.rating}}</span>
                </div>
                <div class="money">
                  <span class="cur" v-show="food.oldPrice">{{food.oldPrice}}</span>
                  <span class="old">{{food.price}}</span>
                </div>
              </div>
            </li>
          </ul>
        </cube-scroll-nav-panel>
      </cube-scroll-nav>
    </div>
  </div>
</template>

<script>
import { getGoods } from "api"; // 数据api
export default {
  name: "goods",
  props: {
    data: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  data() {
    return {
      goods: [],
      current: "",
      scrollOptions: {
        click: false,
        directionLockThreshold: 0
      }
    };
  },
  methods: {
    _fetch() {
      getGoods().then(goods => {
        this.goods = goods;
        console.log(this.data);
      });
    },
    changeHandler(label) {
      console.log("changed to:", label);
    },
    stickyChangeHandler(current) {
      console.log("sticky-change", current);
    }
  }
};
</script>

<style lang="stylus" scoped>
@import '~common/stylus/mixin';
@import '~common/stylus/variable';

.goods {
  position: relative;
  text-align: left;
  height: 100%;
  height: 500px;   // 这里不设置就出不来

  .scroll-nav-wrapper {
    position: absolute;
    width: 100%;
    top: 0;
    left: 0;
    bottom: 48px;
  }

  >>> .cube-scroll-nav-bar {
    width: 80px;
    white-space: normal;
    overflow: hidden;
  }

  >>> .cube-scroll-nav-bar-item {
    display: flex;
    align-items: center;
    height: 54px;
    line-height: 14px;
    padding: 0 12px;
    font-size: $fontsize-small;
    background-color: $color-background-ssss;
  }

  >>> .cube-scroll-nav-bar-item_active {
    background: $color-white;
    color: $color-dark-grey;
  }

  >>> .cube-scroll-nav-panel-title {
    padding-left: 14px;
    height: 26px;
    line-height: 26px;
    border-left: 2px solid $color-col-line;
    font-size: $fontsize-small;
    color: $color-grey;
    background: $color-background-ssss;
  }

  .food-item {
    display: flex;
    margin: 18px;
    padding-bottom: 18px;
    position: relative;

    &:last-child {
      border-none();
      margin-bottom: 0;
    }

    .icon {
      flex: 0 0 57px;
      margin-right: 10px;
    }
  }
}
</style>

写回答

3回答

ustbhuangyi

2019-10-29

你把代码传到 GitHub 上,我抽空看看

1
1
前端是我菜
好的,我一会儿把它传上去,老师有时间帮我看一下。
2019-10-29
共1条回复

前端是我菜

提问者

2019-10-30

这里是我解决后回来分享的代码:

app.vue中:要对tab组件加盒子

<template>
  <div id="app" @touchmove.prevent>
    <v-header :seller="seller"></v-header>
    <div class="tab-wrapper">
      <tab :tabs="tabs"></tab>
    </div>
  </div>
</template>

style:
 #app
    .tab-wrapper
      position: fixed
      top: 136px
      left: 0
      right: 0
      bottom: 0

后面goods、seller、ratings三个组件就不会应为写高度100%而不会出现高度没有,渲染不出来的情况了;

  希望大家可以在看二期视频的时候,也要把最新的代码拿过来对照下,因为可能后期改动的代码,你在视频里是看不到的~~比如我就刚刚才愣过来,哈^_^; 谢谢老师

0
0

前端是我菜

提问者

2019-10-29

      <cube-scroll-nav :side="true" :data="goods" :options="scrollOptions" v-if="goods.length">

这里,我对照了一遍,发现v-if没写,写了之后就可以了,为什么。感觉好像不是太必要呀,也可以不写才对呀?~~~

老师求解

0
3
ustbhuangyi
回复
前端是我菜
https://github.com/ustbhuangyi/vue-sell 建议先和源码比较比较喔~
2019-10-29
共3条回复

Vue.js2.5+cube-ui重构饿了么App(经典再升级)

掌握Vue1.0到2.0再到2.5最全版本应用与迭代,打造极致流畅的WebApp

9868 学习 · 4162 问题

查看课程