怎麼實現通訊錄字母表
參考網站: https://github.com/ustbhuangyi/better-scroll
npm install better-scroll --save
import BScroll from 'better-scroll'
<template>
<div>
<cityheader></cityheader>
<seader></seader>
<list :aases="aases" :bbses="bbses" ></list>
<alphabet :bbses="bbses"></alphabet>
</div>
</template>
<script>
// import axios from 'axios'
import cityheader from './components/header'
import seader from './components/seader'
import list from './components/list'
import alphabet from './components/alphabet'
import axios from 'axios'
export default {
name:'city',
components: {
cityheader,
seader,
list,
alphabet
},
data(){
return {
aases:{}, //熱門城市
bbses:[] //字母表城市
}
},
methods:{
getcityinfo () {
axios.get('/static/mock/city.json')
.then(this.handlecityfo)
},
handlecityfo (res) {
res=res.data
if(res.ret&&res.data){
const data=res.data
this.aases=data.hotCities
this.bbses=data.cities
}
}
},
mounted () {
this.getcityinfo()
}
}
</script>
<style lang="stylus" scoped>
</style>
主體
<template>
<div class="list" ref="wraper">
<div class="">
<div class="area">
<div class="title border-topbottom">當前城市</div>
<div class="button-list">
<div class="button-wrapper">
<div class="button"> 北京</div>
</div>
</div>
</div>
<div class="area">
<div class="title border-topbottom" >熱門城市</div>
<div class="button-list">
<div class="button-wrapper" v-for="item of aases" :key="item.id" >
<div class="button"> {{item.name}}</div>
</div>
</div>
</div>
<div class="area" v-for="(item,key) of bbses" :key="key">
<div class="title border-topbottom">{{key}}</div>
<div class="item-list" >
<div class="item border-bottom"
v-for="instem of item"
:key="instem.id"
>
{{instem.name}}
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import bscroll from 'better-scroll'
export default {
name:'citylist',
props:{
aases:Array,
bbses:Object
},
mounted() {
this.scroll=new bscroll(this.$refs.wraper)
}
}
</script>
<style lang="stylus" scoped>
@import '~styles/varibles.styl'
.border-topbottom
&:before
border-color #cccccc
&:after
border-color #cccccc
.border-bottom
&:before
border-color #cccccc
.list
overflow hidden
position absolute
top 1.58rem
left 0
bottom 0
right 0
.title
line-height .54rem
background #eeeeee
padding-left .2rem
color #666
font-size .26rem
.button-list
padding .1rem 0.6rem .1rem .1rem
overflow hidden
.button-wrapper
float left
width 33.33%
padding .1rem
box-sizing border-box
.button
padding .1rem 0
text-align center
border 0.02rem solid #cccccc
border-radius 0.06rem
.item-list
.item
line-height .76rem
color #666
padding-left .2rem
</style>
滑動
<template>
<div class="list" >
<ul>
<li class="item"
v-for="item of lesttr"
:key="item"
:ref="item"
@touchstart="handtouchstart"
@touchmove="handletouchmove"
@touchend="handletouchend"
@click="handclick"
>{{item}}</li>
</ul>
</div>
</template>
<script>
export default {
name:'cityalphabet',
props:{
bbses:Object
},
data(){
return{
touchstart:false,
starty:0,
tiemr:null
}
},
updated() {
this.starty=this.$refs['A'][0].offsetTop
},
computed:{
lesttr(){
const lesttr=[]
for(let i in this.bbses){
lesttr.push(i)
}
return lesttr
}
},
methods:{
handclick(e){
this.$emit('change',e.target.innerText)
},
handtouchstart(e){
this.touchstart=true
},
handletouchmove(e){
if(this.touchstart){
if(this.timer){ //move 截流操作
clearTimeout(this.tiemr)
}else{
this.timer=setTimeout(()=>{
// const starty= //獲取第一個數字的離父元素的高度
const touchy=e.touches[0].clientY-79 //獲取中間的高度
const indexr =Math.floor((touchy-this.starty)/20)//每一個字母的高度
if(indexr>=0 && indexr <this.lesttr.length ){
this.$emit('change',this.lesttr[indexr]) //觸發事件
}
},20)
}
}
},
handletouchend(e){
this.handletouchend=false
}
}
}
</script>
<style lang="stylus" scoped>
@import '~styles/varibles.styl'
.list
display flex
flex-direction column
justify-content center
position absolute
right 0
top 1.6rem
bottom 0
width .4rem
.item
text-align center
line-height .44rem
color #000
</style>
相關文章
- scrollIntoView()實現通訊錄功能-錨點定位View
- 通訊錄管理系統(C++實現)C++
- 手機通訊錄怎麼備份?手機通訊錄的幾種備份方法
- 動態記憶體開闢實現通訊錄記憶體
- 透過資料結構實現簡易通訊錄資料結構
- 網路通訊2:TCP通訊實現TCP
- 完整版通訊錄(實現簡單具體易上手!!)
- Flutter 城市/通訊錄列表字母索引聯動效果實現Flutter索引
- 教你C語言實現通訊錄的詳細程式碼C語言
- 教你如何用python實現學生通訊錄管理系統Python
- (方法)怎麼快速把電話號碼批量匯入通訊錄
- 匿名管道通訊實現
- java實現UDP通訊JavaUDP
- 電話號碼刪除了怎麼恢復?通訊錄刪除的號碼怎麼找回
- 通訊錄AdressDAO
- 教你:怎麼快速把電話號碼批量匯入手機通訊錄
- 騰訊影片怎麼錄屏,騰訊影片怎麼截長影片
- angular + express 實現websocket通訊AngularExpressWeb
- Java實現TCP通訊程式JavaTCP
- 使用Java實現WebSocket通訊JavaWeb
- golang實現子程式通訊Golang
- 通過 App Groups 實現程式間通訊APP
- 【練手小專案】簡易通訊錄:單連結串列實現
- 如何優雅的實現訊息通訊?
- HTTPS通訊的C++實現HTTPC++
- JAVA通訊(三)——實現多人聊天Java
- C# NModbus RTU通訊實現C#
- C語言實現TCP通訊C語言TCP
- Android Spingboot 實現SSE通訊案例Androidboot
- WebRTC + WebSocket 實現視訊通話Web
- Go語言實現TCP通訊GoTCP
- WebSocket實現前後端通訊Web後端
- sharedWorker 實現多頁面通訊
- 揭祕:中興通訊怎麼了?
- Uniapp 使用 GoEasy 實現 websocket 實時通訊APPGoWeb
- 怎麼錄製QQ語音通話 QQ通話錄音軟體哪個好?
- JAVA通訊(二)——實現客戶機和伺服器通訊Java伺服器
- 即時通訊發展前景怎麼樣?現在狀態是如何