亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue實現(xiàn)歌手列表字母排序下拉滾動條側(cè)欄排序?qū)崟r更新

 更新時間:2019年05月14日 08:32:37   作者:jianpiao  
這篇文章主要介紹了vue實現(xiàn)歌手列表字母排序,下拉滾動條側(cè)欄排序?qū)崟r更新,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下

今天寫項目的時候遇到了歌手排序的問題,聯(lián)想到了我們平時的手機通訊錄側(cè)欄字母排序,按照ABCDE這樣的順序?qū)γ诌M行排序。

我們先來看看效果


那就用vue來實現(xiàn)一遍

首先新建一個vue頁面,取名為helloworld.vue

在頁面里寫入內(nèi)容

<template>
 <div class="hello">
 <div class="singer" id="singer">
  <div class="singer-top-tag">{{singerTopTag | filterSingerTag}}</div>
  <ul class="singer-ul">
  <li v-for="(item, index) in list" :key="index" class="singer-ul-li">
   <div class="singer-tag" :id="item.tag">{{item.tag | filterSingerTag}}</div>
   <ul>
   <li v-for="(fitem, findex) in item.data" :key="findex">
    <img :src="`https://y.gtimg.cn/music/photo_new/T001R300x300M000${fitem.Fsinger_mid}.jpg?max_age=2592000`">
    <div>{{fitem.Fsinger_name}}</div>
   </li>
   </ul>
  </li>
  </ul>
 </div>
 <div class="sort">
  <ul>
  <li 
  v-for="(item, index) in sortList" 
  :key="index" 
  @click="jumpTag(item)"
  :class="{current:currentSort == item ? true : false}"
  >
   {{item == `hot` ? `熱` : item}}
  </li>
  </ul>
 </div>
 </div>
</template>
<script>
import axios from 'axios'
export default {
 name: "HelloWorld",
 data() {
 return {
  list:[], // 歌手列表
  sortList:[], // 側(cè)欄排序列表
  currentSort: 'hot', // 當(dāng)前排序的標(biāo)簽
  singerTopTag: 'hot', // 歌手欄頭部的標(biāo)簽名字
 };
 },
 mounted() {
 this.testData()
 // 監(jiān)聽滾動條
 window.addEventListener('scroll', this.handleScroll)
 },
 destroyed () {
 // 頁面摧毀的時候要關(guān)閉監(jiān)聽 
 window.removeEventListener('scroll', this.handleScroll)
 },
 methods: {
 handleScroll () {
  let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
  let offsetTop = 0
  this.list.forEach((item,index) => {
  // 獲取每個排序標(biāo)簽的位置
  offsetTop = document.querySelectorAll('.singer-ul-li')[index].offsetTop
  // 當(dāng)前滾動條的位置 和 當(dāng)前的標(biāo)簽偏移頂部的距離進行對比
  // 每一個歌手的li標(biāo)簽的高度必須要保持一致,我這里的高度是70,可以計算自己項目的內(nèi)容的具體高度進行修改
  if (scrollTop > offsetTop && scrollTop < (offsetTop+ 70*item.data.length)) {
   this.singerTopTag = item.tag
   this.currentSort = item.tag
  }
  })
 },
 // 請求數(shù)據(jù)
 testData(){
  axios.get(`https://c.y.qq.com/v8/fcg-bin/v8.fcg?g_tk=1928093487&inCharset=utf-8&outCharset=utf-8&notice=0&format=jsonp&channel=singer&page=list&key=all_all_all&pagesize=100&pagenum=1&hostUin=0&needNewCode=0&platform=yqq&jsonpCallback=jp1`)
  .then(res => {
  res = res.data.substring(5,res.data.length-1)
  res = JSON.parse(res).data.list
  res = res.sort((a,b) => a.Findex.localeCompare(b.Findex))
  res.forEach((item,index) => {
   // 添加側(cè)欄排序
   item.Findex = item.Findex == 9 ? 'hot' : item.Findex
   this.sortList.push(item.Findex)
  })
  // 去除重復(fù)
  this.sortList = new Set(this.sortList)
  this.sortList = [...this.sortList]
  // 添加排序標(biāo)簽和歌手列表
  this.sortList.forEach(e => {
   this.list.push({
   tag:e,
   data:res.filter(i => i.Findex ==e)
   })
  })
  })
 },
 // 跳轉(zhuǎn)標(biāo)簽
 jumpTag(i){
  this.singerTopTag = i
  this.currentSort = i
  document.querySelector(`#${i}`).scrollIntoView()
 }
 },
 filters :{
 filterSingerTag(i) {
  return i == `hot` ? `熱門` : i
 }
 }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.hello {
 position: relative;
 background-color: #222;
}

.singer {
 position: relative;
 width: 100%;
 height: 100%;
 overflow: hidden;
 background: #222;
}

.singer-top-tag {
 position: fixed;
 top: 0px;
 left: 0;
 width: 100%;
 height: 30px;
 line-height: 30px;
 padding-left: 20px;
 font-size: 12px;
 color: hsla(0,0%,100%,.5);
 background: #333;
}

.singer-tag {
 width: 100%;
 height: 30px;
 margin-bottom: 20px;
 line-height: 30px;
 padding-left: 20px;
 font-size: 12px;
 color: hsla(0,0%,100%,.5);
 background: #333;
}

.singer-ul-li ul li {
 list-style-type: none;
 display: flex;
 justify-content: flex-start;
 align-items: center;
 padding: 0 0 20px 20px;
 color: rgba(255, 255, 255, .5);
}

.singer-ul-li ul li img {
 border-radius: 50%;
 widows: 50px;
 height: 50px;
}

.singer-ul-li ul li div {
 padding-left: 20px;
}

.sort {
 position: fixed;
 z-index: 30;
 right: 0;
 top: 50%;
 -webkit-transform: translateY(-50%);
 transform: translateY(-50%);
 width: 20px;
 padding: 20px 0;
 border-radius: 10px;
 text-align: center;
 background: rgba(0,0,0,.3);
 font-family: Helvetica;
}

ul {
 margin: 0;
 padding: 0;
}

.sort ul{
 color: rgba(255,255,255,.6);
}

.sort ul li {
 list-style-type: none;
 padding: 3px;
 line-height: 1;
 font-size: 12px;
}

.current {
 color: #ffcd32;
}
</style>

我是使用的qq音樂接口,獲取的數(shù)據(jù)需要進行處理,如果覺得麻煩可以自己寫靜態(tài)數(shù)據(jù)來代替

數(shù)據(jù)的格式

const list = [
 {
  tag:`A`,
  data:[
   {
    img:`https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1558361071&di=0a522afe68fc7e2aa3af34cb5cd8c96a&imgtype=jpg&er=1&src=http%3A%2F%2Fwerkstette.dk%2Fwp-content%2Fuploads%2F2015%2F09%2FEntertainment_Weekly_Photographer_Marc_Hom_British_Actor_Charlie_Hunnam_as_King_Arthur_Retouch_Werkstette10-770x841.jpg`,
    Fsinger_name:`奧巴里`
  }
  ]
 },
 {
  tag:`B`,
  data:[
   {
    img:`https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1558361071&di=0a522afe68fc7e2aa3af34cb5cd8c96a&imgtype=jpg&er=1&src=http%3A%2F%2Fwerkstette.dk%2Fwp-content%2Fuploads%2F2015%2F09%2FEntertainment_Weekly_Photographer_Marc_Hom_British_Actor_Charlie_Hunnam_as_King_Arthur_Retouch_Werkstette10-770x841.jpg`,
    Fsinger_name:`BIGBANG`
  }
  ]
 },
 {
  tag:`C`,
  data:[
   {
    img:`https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1558361071&di=0a522afe68fc7e2aa3af34cb5cd8c96a&imgtype=jpg&er=1&src=http%3A%2F%2Fwerkstette.dk%2Fwp-content%2Fuploads%2F2015%2F09%2FEntertainment_Weekly_Photographer_Marc_Hom_British_Actor_Charlie_Hunnam_as_King_Arthur_Retouch_Werkstette10-770x841.jpg`,
    Fsinger_name:`蔡依林`
  }
  ]
 },
 {
  tag:`D`,
  data:[
   {
    img:`https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1558361071&di=0a522afe68fc7e2aa3af34cb5cd8c96a&imgtype=jpg&er=1&src=http%3A%2F%2Fwerkstette.dk%2Fwp-content%2Fuploads%2F2015%2F09%2FEntertainment_Weekly_Photographer_Marc_Hom_British_Actor_Charlie_Hunnam_as_King_Arthur_Retouch_Werkstette10-770x841.jpg`,
    Fsinger_name:`鄧紫棋`
  }
  ]
 },
]

再者還要注意頁面的img標(biāo)簽,直接復(fù)制上面的數(shù)據(jù)的話要對img標(biāo)簽進行修改,去掉http那一串,直接用:src="item.img"代替

const list = [
 {
  tag:`A`,
  data:[
   {
    img:`https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1558361071&di=0a522afe68fc7e2aa3af34cb5cd8c96a&imgtype=jpg&er=1&src=http%3A%2F%2Fwerkstette.dk%2Fwp-content%2Fuploads%2F2015%2F09%2FEntertainment_Weekly_Photographer_Marc_Hom_British_Actor_Charlie_Hunnam_as_King_Arthur_Retouch_Werkstette10-770x841.jpg`,
    Fsinger_name:`奧巴里`
  }
  ]
 },
 {
  tag:`B`,
  data:[
   {
    img:`https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1558361071&di=0a522afe68fc7e2aa3af34cb5cd8c96a&imgtype=jpg&er=1&src=http%3A%2F%2Fwerkstette.dk%2Fwp-content%2Fuploads%2F2015%2F09%2FEntertainment_Weekly_Photographer_Marc_Hom_British_Actor_Charlie_Hunnam_as_King_Arthur_Retouch_Werkstette10-770x841.jpg`,
    Fsinger_name:`BIGBANG`
  }
  ]
 },
 {
  tag:`C`,
  data:[
   {
    img:`https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1558361071&di=0a522afe68fc7e2aa3af34cb5cd8c96a&imgtype=jpg&er=1&src=http%3A%2F%2Fwerkstette.dk%2Fwp-content%2Fuploads%2F2015%2F09%2FEntertainment_Weekly_Photographer_Marc_Hom_British_Actor_Charlie_Hunnam_as_King_Arthur_Retouch_Werkstette10-770x841.jpg`,
    Fsinger_name:`蔡依林`
  }
  ]
 },
 {
  tag:`D`,
  data:[
   {
    img:`https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1558361071&di=0a522afe68fc7e2aa3af34cb5cd8c96a&imgtype=jpg&er=1&src=http%3A%2F%2Fwerkstette.dk%2Fwp-content%2Fuploads%2F2015%2F09%2FEntertainment_Weekly_Photographer_Marc_Hom_British_Actor_Charlie_Hunnam_as_King_Arthur_Retouch_Werkstette10-770x841.jpg`,
    Fsinger_name:`鄧紫棋`
  }
  ]
 },
]

總結(jié)

以上所述是小編給大家介紹的vue實現(xiàn)歌手列表字母排序下拉滾動條側(cè)欄排序?qū)崟r更新,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

  • 在Echarts圖中給坐標(biāo)軸加一個標(biāo)識線markLine

    在Echarts圖中給坐標(biāo)軸加一個標(biāo)識線markLine

    這篇文章主要介紹了在Echarts圖中給坐標(biāo)軸加一個標(biāo)識線markLine,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • vue按需引入element Transfer 穿梭框

    vue按需引入element Transfer 穿梭框

    這篇文章主要介紹了vue按需引入element Transfer 穿梭框的相關(guān)資料,需要的朋友可以參考下
    2017-09-09
  • vue+ts實現(xiàn)元素鼠標(biāo)拖動效果

    vue+ts實現(xiàn)元素鼠標(biāo)拖動效果

    這篇文章主要為大家詳細介紹了vue+ts實現(xiàn)元素鼠標(biāo)拖動效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • Vue Element前端應(yīng)用開發(fā)之整合ABP框架的前端登錄

    Vue Element前端應(yīng)用開發(fā)之整合ABP框架的前端登錄

    VUE+Element 前端是一個純粹的前端處理,前面介紹了很多都是Vue+Element開發(fā)的基礎(chǔ),從本章隨筆開始,就需要進入深水區(qū)了,需要結(jié)合ABP框架使用
    2021-05-05
  • vue2中vue-router引入使用詳解

    vue2中vue-router引入使用詳解

    Vue?Router?是?Vue?的官方路由,它與?Vue.js?核心深度集成,讓用?Vue.js?構(gòu)建單頁應(yīng)用變得輕而易舉,下面就跟隨小編一起學(xué)習(xí)一下vue-router的具體用法吧
    2023-12-12
  • Vue3+script setup+ts+Vite+Volar搭建項目

    Vue3+script setup+ts+Vite+Volar搭建項目

    本文主要介紹了Vue3+script setup+ts+Vite+Volar搭建項目,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • vue draggable resizable 實現(xiàn)可拖拽縮放的組件功能

    vue draggable resizable 實現(xiàn)可拖拽縮放的組件功能

    這篇文章主要介紹了vue draggable resizable 實現(xiàn)可拖拽縮放的組件功能,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-07-07
  • Vue項目每次發(fā)版后要清理瀏覽器緩存問題解決辦法

    Vue項目每次發(fā)版后要清理瀏覽器緩存問題解決辦法

    最近項目更新頻繁,每次一更新客戶都說還跟之前的一樣,一查原因是因為客戶沒有清空瀏覽器的緩存,所以為了方便客戶看到最新版本,開始調(diào)研再發(fā)布新版本后自動清理緩存,這篇文章主要給大家介紹了關(guān)于Vue項目每次發(fā)版后要清理瀏覽器緩存問題的解決辦法,需要的朋友可以參考下
    2024-02-02
  • 詳解Vue2中組件間通信的解決全方案

    詳解Vue2中組件間通信的解決全方案

    Vue中組件這個特性讓不少前端er非常喜歡,我自己也是其中之一,它讓前端的組件式開發(fā)更加合理和簡單。下面這篇文章主要給大家介紹了關(guān)于Vue2中組件間通信的解決全方案,文中通過示例代碼介紹的非常詳細,需要的朋友們下面來一起看看吧。
    2017-07-07
  • vuex頁面刷新導(dǎo)致數(shù)據(jù)丟失的解決方案

    vuex頁面刷新導(dǎo)致數(shù)據(jù)丟失的解決方案

    這篇文章主要介紹了vuex頁面刷新導(dǎo)致數(shù)據(jù)丟失的解決方案,幫助大家更好的使用vue框架,感興趣的朋友可以了解下
    2020-12-12

最新評論