<script>
import iIndex from 'iview-mpvue/dist/components/index-list/index-list'
export default {
components: {
'i-index': iIndex
}
}
</script>
import 'iview-mpvue/dist/components/index-list/style/css'
<div class="i-index-demo">
<i-index height="100%" :data-set="cities" i-item-class="i-index-demo-item" v-on:change="onChange"></i-index>
</div>
<script>
import { cities } from './city' // 城市列表数据
export default {
...
data() {
let storeCity = new Array(26)
const words = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
words.forEach((item,index)=>{
storeCity[index] = {
key : item,
list : []
}
})
cities.forEach((item)=>{
let firstName = item.pinyin.substring(0,1)
let index = words.indexOf( firstName )
storeCity[index].list.push({
name : item.name,
key : firstName
})
})
return {
cities: storeCity
}
},
methods: {
onChange(opts) {
// todo
}
}
}
</script>