Vue全家桶—项目实战_4

1、把city.vue中的content内容封装到city-group.vue中

使用vant3中的标签

<van-index-bar :sticky="false" :index-list="indexList">
      <van-index-anchor index="热门" />
      <div class="list">
        <template v-for="(city, index) in groupData.hotCities">
          <div class="city" @click="cityClick(city)">{{ city.cityName }}</div>
        </template>
      </div>

      <template v-for="(group, index) in groupData.cities" :key="index">
        <van-index-anchor :index="group.group" />
        <template v-for="(city, indey) in group.cities" :key="indey">
          <van-cell :title="city.cityName" @click="cityClick(city)" />
        </template>
      </template>
    </van-index-bar>

 

// 定义props
const props = defineProps({
  groupData: {
    type: Object,
    default: () => ({})
  }
})


2、在city.vue中,因为获取两个title网速太慢可进行优化content

<template v-for="(value, key, index) in allCities">

        <city-group v-show="tabActive === key" :group-data="value" />

      </template>


3、热门  分组

<van-index-anchor index="热门" />

      <div class="list">

        <template v-for="(city, index) in groupData.hotCities">

          <div class="city" @click="cityClick(city)">{{ city.cityName }}</div>

        </template>

      </div>

 

// 动态的索引

const indexList = computed(() => {

  const list = props.groupData.cities.map(item => item.group)

  list.unshift("#")

  return list

})

// 监听城市的点击

const router = useRouter()

const cityStore = useCityStore()

const cityClick = (city) => {

  // 选中当前城市 store共享数据

  cityStore.currentCity = city

 

  // 返回上一级

  router.back()

}

 

在city.js中

 currentCity: {
      cityName: "广州"
    }

 

数据回显在home-search-box中回显

const cityStore = useCityStore()

const { currentCity } = storeToRefs(cityStore)

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值