美文网首页
vue点击左侧,右边滚动到最上面

vue点击左侧,右边滚动到最上面

作者: Amanda妍 | 来源:发表于2023-01-04 16:58 被阅读0次
image.png
 <div class="ingredients-list">
          <div class="ingredient-item" v-for="(item, index) in $tools.metadata.foodBankType" :class="{'active': index === activeFoodIndredientIndex}" @click="selectFood(item, index)">
            <span class="name">{{ item.label }}</span>
          </div>
        </div>
        <div class="food-container" ref="rightFoodList">
          <div class="food-item-select" v-for="item in rightFoodList" :key="item.id">
            <div class="select-left">
              <div class="food-name">{{ item.name }}</div>
              <div class="food-energe">
                <span class="value">{{ item.kcal ? (item.kcal).toFixed(2) : '' }}</span>
                <span>千卡/100g</span>
              </div>
            </div>
            <!--            添加食物-->
            <img class="add-icon" @click.stop="showSelectFood(item)" src="https://cdn.xun-qi.cn/seer/base/upload/img/1671074807714.png"/>
          </div>
        </div>


js部分


selectFood(item, index) {
      this.activeFoodIndredientIndex = index
      this.query.type = item.value
      this.refresh()
    },`

 refresh() {
      this.setLoading(true)
      this.loadYingKangFoodBank({
        search: this.query.search,
        type: this.query.type,
        callback: (res) => {
          console.log(res)
          this.rightFoodList = res.data.content
          this.setLoading(false)
          this.$nextTick(()=>{
            let top = this.$refs.rightFoodList.scrollTop
            // 定时改变高度,实现滚动效果
            const timeTop = setInterval(() => {
              this.$refs.rightFoodList.scrollTop = top -= 30;
              if (top <= 0) {
                clearInterval(timeTop);
              }
            }, 10);
          })
        }
      })
    },

相关文章

网友评论

      本文标题:vue点击左侧,右边滚动到最上面

      本文链接:https://www.haomeiwen.com/subject/enarcdtx.html