最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

我們先來(lái)看看效果


那就用vue來(lái)實(shí)現(xiàn)一遍

首先新建一個(gè)vue頁(yè)面,取名為helloworld.vue

在頁(yè)面里寫(xiě)入內(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)聽(tīng)滾動(dòng)條
 window.addEventListener('scroll', this.handleScroll)
 },
 destroyed () {
 // 頁(yè)面摧毀的時(shí)候要關(guān)閉監(jiān)聽(tīng) 
 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) => {
  // 獲取每個(gè)排序標(biāo)簽的位置
  offsetTop = document.querySelectorAll('.singer-ul-li')[index].offsetTop
  // 當(dāng)前滾動(dòng)條的位置 和 當(dāng)前的標(biāo)簽偏移頂部的距離進(jìn)行對(duì)比
  // 每一個(gè)歌手的li標(biāo)簽的高度必須要保持一致,我這里的高度是70,可以計(jì)算自己項(xiàng)目的內(nèi)容的具體高度進(jìn)行修改
  if (scrollTop > offsetTop && scrollTop < (offsetTop+ 70*item.data.length)) {
   this.singerTopTag = item.tag
   this.currentSort = item.tag
  }
  })
 },
 // 請(qǐng)求數(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` ? `熱門(mén)` : 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音樂(lè)接口,獲取的數(shù)據(jù)需要進(jìn)行處理,如果覺(jué)得麻煩可以自己寫(xiě)靜態(tài)數(shù)據(jù)來(lái)代替

數(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:`鄧紫棋`
  }
  ]
 },
]

再者還要注意頁(yè)面的img標(biāo)簽,直接復(fù)制上面的數(shù)據(jù)的話要對(duì)img標(biāo)簽進(jìn)行修改,去掉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實(shí)現(xiàn)歌手列表字母排序下拉滾動(dòng)條側(cè)欄排序?qū)崟r(shí)更新,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

  • vue項(xiàng)目中使用websocket的實(shí)現(xiàn)

    vue項(xiàng)目中使用websocket的實(shí)現(xiàn)

    本文主要介紹了vue項(xiàng)目中使用websocket的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • vue2.0項(xiàng)目中使用Ueditor富文本編輯器示例代碼

    vue2.0項(xiàng)目中使用Ueditor富文本編輯器示例代碼

    本篇文章主要介紹了vue2.0項(xiàng)目中使用Ueditor富文本編輯器示例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下
    2017-08-08
  • 前端Uniapp使用Vant打造Uniapp項(xiàng)目避坑指南

    前端Uniapp使用Vant打造Uniapp項(xiàng)目避坑指南

    這篇文章主要給大家介紹了關(guān)于前端Uniapp使用Vant打造Uniapp項(xiàng)目避坑的相關(guān)資料,Uniapp結(jié)合Vant可以快速構(gòu)建跨平臺(tái)移動(dòng)應(yīng)用,通過(guò)HBuilderX安裝和配置Vant組件,解決了樣式識(shí)別問(wèn)題,并實(shí)現(xiàn)了組件的全局注冊(cè),需要的朋友可以參考下
    2024-11-11
  • Vue插件報(bào)錯(cuò):Vue.js is detected on this page.問(wèn)題解決

    Vue插件報(bào)錯(cuò):Vue.js is detected on this page.問(wèn)題解決

    這篇文章主要介紹了Vue插件報(bào)錯(cuò):Vue.js is detected on this page.問(wèn)題解決,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • Vue Element前端應(yīng)用開(kāi)發(fā)之前端API接口的封裝

    Vue Element前端應(yīng)用開(kāi)發(fā)之前端API接口的封裝

    對(duì)整個(gè)系統(tǒng)來(lái)說(shuō),一般會(huì)有很多業(yè)務(wù)對(duì)象,而每個(gè)業(yè)務(wù)對(duì)象的API接口又有很多。我們這個(gè)VUE+Element 前端應(yīng)用就是針對(duì)ABP框架的業(yè)務(wù)對(duì)象,因此前端的業(yè)務(wù)對(duì)象接口也是比較統(tǒng)一的,那么可以考慮在前端中對(duì)后端API接口調(diào)用進(jìn)行封裝,引入ES6的方式進(jìn)行前端API的抽象簡(jiǎn)化。
    2021-05-05
  • Vue項(xiàng)目全局配置微信分享思路詳解

    Vue項(xiàng)目全局配置微信分享思路詳解

    這篇文章給大家介紹了vue項(xiàng)目全局配置微信分享思路講解,使用vue作為框架,使用vux作為ui組件庫(kù),具體內(nèi)容詳情大家跟隨腳本之家小編一起學(xué)習(xí)吧
    2018-05-05
  • VScode更新后安裝vetur仍無(wú)法格式化vue文件的解決

    VScode更新后安裝vetur仍無(wú)法格式化vue文件的解決

    這篇文章主要介紹了VScode更新后安裝vetur仍無(wú)法格式化vue文件的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • vue2 elementui if導(dǎo)致的rules判斷失效的解決方法

    vue2 elementui if導(dǎo)致的rules判斷失效的解決方法

    文章討論了在使用Vue2和ElementUI時(shí),將if語(yǔ)句放在el-form-item內(nèi)導(dǎo)致rules判斷失效的問(wèn)題,并提出了將判斷邏輯移到外部的解決方案,感興趣的朋友一起看看吧
    2024-12-12
  • Vue項(xiàng)目Nginx子目錄部署(Vite和Vue-CLI)

    Vue項(xiàng)目Nginx子目錄部署(Vite和Vue-CLI)

    本文主要介紹了Vue項(xiàng)目Nginx子目錄部署(Vite和Vue-CLI),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2024-05-05
  • 在Vue3項(xiàng)目中關(guān)閉ESLint的完整步驟

    在Vue3項(xiàng)目中關(guān)閉ESLint的完整步驟

    實(shí)際上在學(xué)習(xí)過(guò)程中,你會(huì)發(fā)現(xiàn)eslint檢查特別討厭,這個(gè)時(shí)候我們需要關(guān)閉掉eslint檢查,下面這篇文章主要給大家介紹了關(guān)于在Vue3項(xiàng)目中關(guān)閉ESLint的完整步驟,需要的朋友可以參考下
    2023-11-11

最新評(píng)論

鹤庆县| 神木县| 普格县| 兴仁县| 南昌市| 巧家县| 图片| 曲沃县| 蓝田县| 尼勒克县| 温州市| 永定县| 修文县| 潢川县| 商丘市| 沛县| 康平县| 拜泉县| 长岭县| 绍兴县| 偏关县| 千阳县| 惠东县| 岳阳市| 土默特左旗| 鄂伦春自治旗| 克什克腾旗| 兴文县| 清丰县| 怀安县| 禹州市| 皋兰县| 甘南县| 英德市| 瑞安市| 孟津县| 青龙| 博罗县| 贞丰县| 娱乐| 竹山县|