索引栏
实现城市列表页

一、安装

  1. npm i vant -S

二、使用

  1. //main.js中配置
  2. import Vue from 'vue';
  3. import Vant from 'vant';
  4. import 'vant/lib/index.css';
  5. Vue.use(Vant)

三、代码

  1. <template>
  2. <van-index-bar class="content">
  3. <div>
  4. <h1>热门城市</h1>
  5. <ul class="wrapper">
  6. <li v-for="city of hotCities" :key="city.name">{{city.name}}</li>
  7. </ul>
  8. </div>
  9. <div v-for="(item,index) of cities" :key="index">
  10. <van-index-anchor :index="index" />
  11. <van-cell v-for="city of item" :key="city.name" :title="city.name" />
  12. </div>
  13. </van-index-bar>
  14. </template>
  15. <script>
  16. export default {
  17. name: "City",
  18. data() {
  19. return {
  20. hotCities: [],
  21. cities: ""
  22. };
  23. },
  24. mounted: async function() {
  25. var url = "https://easy-mock.com/mock/5d313b5dcac88245d6b0b79a/movie/city";
  26. var res = await this.axios.get(url);
  27. var data = res.data.data;
  28. this.handleCity(data);
  29. },
  30. methods: {
  31. handleCity(data) {
  32. var { hotCities, cities } = data;
  33. this.hotCities = hotCities;
  34. this.cities = cities;
  35. }
  36. }
  37. };
  38. </script>
  39. <style scoped >
  40. .wrapper{
  41. margin-top: 20px;
  42. display: grid;
  43. grid-template-columns: 1fr 1fr 1fr;
  44. align-items: center;
  45. justify-items: center;
  46. grid-row-gap: 20px;
  47. }
  48. .wrapper>li{
  49. width:80%;
  50. height: 60px;
  51. border:1px solid #eee;
  52. text-align: center;
  53. border-radius: 15px;
  54. line-height: 60px;
  55. }
  56. .content {
  57. font-size: 30px;
  58. margin-top: 250px;
  59. }
  60. .content >>>.van-index-bar__index {
  61. margin-top: 20px;
  62. }
  63. .content >>> .van-hairline--bottom {
  64. z-index: 0 !important;
  65. }
  66. .content >>> .van-cell {
  67. line-height: 60px;
  68. }
  69. </style>