vue-music(19)mixin的使用及di底部scroll刷新的实现

当多个组件都用到共同的一些js代码时候,可以吧这些代码抽象出来,放在mixin中,用到的时候引用

export const playlistMixin = {
  computed: {
    ...mapGetters([
      'playList'
    ])
  },
  mounted () { // 渲染完毕后触发
    this.handlePlayList(this.playList)
  },
  activated () { // keep-alive 切换的时候 触发
    this.handlePlayList(this.playList)
  },
  watch: {
    playList (newList) {
      this.handlePlayList(newList)
    }
  }
}

在组件引用

import {playlistMixin } from 'xxx.js'

export default {
    mixins:[playlistMixin]
    //之后再写需要的方法替换mixin中的共有方法
    handlePlayList (playList) {
      const bottom = this.playList.length > 0 ? '60px' : 0 // 当存在破防徐建时候,组件的bottom为60px
      this.$refs.shortcutWrapper.style.bottom = bottom
      this.$refs.shortcut.refresh() // 调用scrool内部接口刷新
      this.$refs.searchResult.style.bottom = bottom
      this.$refs.suggest.refresh()
    },

当scroll包含两部分,而且两部分都是通过一部获取的,要等二者全部加载完毕后再刷新
可以将两部分合并成一个数组:

<scroll class="shortcut" :data="shortcut" ref="shortcut">

。。。
shortcut () {
      return this.hotKey.concat(this.searchHistory)
      // 当hotKey和History有一个发生变化的时候。computed就会重新计算。
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值