怎麼實現通訊錄字母表
參考網站: 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>
相關文章
- 利用SQL實現通訊錄SQL
- 呼叫通訊錄實現思路
- 簡單通訊錄的實現
- 手機通訊錄怎麼備份?手機通訊錄的幾種備份方法
- 通訊錄管理系統(C++實現)C++
- 360手機衛士怎麼進入微通訊錄
- scrollIntoView()實現通訊錄功能-錨點定位View
- 百度雲裡怎麼進行通訊錄同步
- 網路通訊2:TCP通訊實現TCP
- 透過資料結構實現簡易通訊錄資料結構
- css模擬實現手機通訊錄佈局效果CSS
- Vue元件通訊實踐記錄Vue元件
- (方法)怎麼快速把電話號碼批量匯入通訊錄
- 匿名管道通訊實現
- java實現UDP通訊JavaUDP
- 沉寂的通訊錄 | 閨蜜是什麼?
- js通訊錄效果,你見過麼JS
- 電話號碼刪除了怎麼恢復?通訊錄刪除的號碼怎麼找回
- Flutter 城市/通訊錄列表字母索引聯動效果實現Flutter索引
- 教你C語言實現通訊錄的詳細程式碼C語言
- 完整版通訊錄(實現簡單具體易上手!!)
- Android使用RecycleView實現魅族手機通訊錄介面AndroidView
- 揭祕:中興通訊怎麼了?
- 教你:怎麼快速把電話號碼批量匯入手機通訊錄
- golang實現子程式通訊Golang
- Java實現TCP通訊程式JavaTCP
- angular + express 實現websocket通訊AngularExpressWeb
- 使用Java實現WebSocket通訊JavaWeb
- 教你如何用python實現學生通訊錄管理系統Python
- ios實現本地通訊錄點選(標識)跳轉APPiOSAPP
- C# 通過socket實現UDP 通訊C#UDP
- Nginx和php是怎麼通訊的?NginxPHP
- 叢集RPC通訊怎麼做RPC
- 使用Oracle實現實時通訊(轉)Oracle
- 如何優雅的實現訊息通訊?
- 通訊錄AdressDAO
- python怎麼實現發現所需目錄不存在時新建目錄Python
- iOS基於Socket.io即時通訊IM實現,WebRTC實現視訊通話iOSWeb