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

1. switches.vue组件:

《vue-music:添加歌曲到队列add-song.vue》上传中…]

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

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栏切换,两个滚动列表边界逻辑

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

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'
    ])
  }
}
    原文作者:云深不知处
    原文地址: https://segmentfault.com/a/1190000017512082
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞