vue-music:添加歌曲到队列add-song.vue

1. switches.vue组件:

clipboard.png上传中...]

组件原则:解耦
在这个组件中,将点击组件的索引传播即可

methods: {
    switchItem(index) {
      this.$emit('switch', index)
    }
}

高亮样式

.switch-item
    flex: 1
    padding: 8px
    text-align: center
    font-size: $font-size-medium
    color: $color-text-d
    &.active
      background: $color-highlight-background
      color: $color-text

2.tab栏切换,两个滚动列表边界逻辑

clipboard.png

1.在watch中
query(newVal) {
  //切换tab栏的时候,刷新scroll
  if (!newVal) {
    this.refreshList()
  }
}
2. methods中定义方法,刷新两个滚动组件
refreshList() {
  setTimeout(() => {
    if (this.currentIndex === 0) {
      this.$refs.songList.refresh()
    } else {
      this.$refs.searchList.refresh()
    }
  }, 20)
},

3. add-song.vue和search.vue: mixin

两个组件有公共方法,所以使用mixin

export const searchMixin = {
  data() {
    return {
      query: '',
      refreshDelay: 120
    }
  },
  computed: {
    ...mapGetters([
      'searchHistory'
    ])
  },
  methods: {
    onQueryChange(query) {
      this.query = query
    },
    //开始滚动的时候输入框的键盘收缩,调用子组件中input,blur事件,收缩键盘
    blurInput() {
      this.$refs.searchBox.blur()
    },
    addQuery() {
      this.$refs.searchBox.setQuery(this.query)
    },
    //保存搜索历史
    saveSearch() {
      this.saveSearchHistory(this.query)
    },
    ...mapActions([
      'saveSearchHistory',
      'deleteSearchHistory'
    ])
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值