请求类型传输

master
dongmu 1 year ago
parent 6da146785a
commit 3ee987f1f9

@ -1,44 +1,39 @@
<script setup lang="ts">
import type { BannerItem } from '@/types/home'
import { ref } from 'vue'
const activeIndex = ref(0)
const onchange: UniHelper.SwiperOnChange = (ev) => {
//
activeIndex.value = ev.detail!.current
}
// props --- ()
defineProps<{
list: BannerItem[]
}>()
// const props = defineProps<{
// list: BannerItem[]
// }>()
// console.log(props, 'props')
</script>
<template>
<view class="carousel">
<swiper :circular="true" :autoplay="false" :interval="3000">
<swiper-item>
<navigator url="/pages/index/index" hover-class="none" class="navigator">
<image
mode="aspectFill"
class="image"
src="https://pcapi-xiaotuxian-front-devtest.itheima.net/miniapp/uploads/slider_1.jpg"
></image>
</navigator>
</swiper-item>
<swiper-item>
<navigator url="/pages/index/index" hover-class="none" class="navigator">
<image
mode="aspectFill"
class="image"
src="https://pcapi-xiaotuxian-front-devtest.itheima.net/miniapp/uploads/slider_2.jpg"
></image>
</navigator>
</swiper-item>
<swiper-item>
<swiper @change="onchange" :circular="true" :autoplay="false" :interval="3000">
<swiper-item v-for="item in list" :key="item.id">
<navigator url="/pages/index/index" hover-class="none" class="navigator">
<image
mode="aspectFill"
class="image"
src="https://pcapi-xiaotuxian-front-devtest.itheima.net/miniapp/uploads/slider_3.jpg"
></image>
<image mode="aspectFill" class="image" :src="item.imgUrl"></image>
</navigator>
</swiper-item>
</swiper>
<!-- 指示点 -->
<view class="indicator">
<text
v-for="(item, index) in 3"
v-for="(item, index) in list.length"
:key="item"
class="dot"
:class="{ active: index === activeIndex }"

@ -1,11 +1,29 @@
<script setup lang="ts">
//
import { getHomeBannerAPI } from '@/services/home'
import CustomNavbar from './componets/CustomNavbar.vue'
import { onLoad } from '@dcloudio/uni-app' // -----
import { ref } from 'vue'
import type { BannerItem } from '@/types/home'
const bannerList = ref<BannerItem[]>([]) //ref([]) BannerItem --- crtrl+i
const getHomeBannerData = async () => {
const res = await getHomeBannerAPI()
bannerList.value = res.result //res.result res.result
}
// --
onLoad(() => {
getHomeBannerData()
})
</script>
<template>
<CustomNavbar></CustomNavbar>
<XtxSwiper></XtxSwiper>
<!-- 自定义轮播图 ctrl+点击 后先进入的是组件类型 声明文件 可以看到组件引入的路径-->
<XtxSwiper :list="bannerList"></XtxSwiper>
<view class="index">index</view>
</template>

@ -0,0 +1,17 @@
// 存放路径: src/services/home.ts
import type { BannerItem } from '@/types/home'
import { http } from '@/utils/http'
/**
* -广-
* @param distributionSite 广 12 1
*/
export const getHomeBannerAPI = (distributionSite = 1) => {
return http<BannerItem[]>({
method: 'GET',
url: '/home/banner',
data: {
distributionSite,
},
})
}

@ -0,0 +1,11 @@
/** 首页-广告区域数据类型 */
export type BannerItem = {
/** 跳转链接 */
hrefUrl: string
/** id */
id: string
/** 图片链接 */
imgUrl: string
/** 跳转类型 */
type: number
}
Loading…
Cancel
Save