<template>
<view>
轮播图
</view>
</template>
<script>
export default {
data(){
return{
swipers:[]
}
},
methods:{
// 获取轮播图的数据
getSwipers(){ // 每次打开页面都会调用数据 在生命周期中 onload页面声明周期最适合
console.log("获取轮播图数据")
// 发送请求获取数据 文档API 网络 发起请求
uni.request({
url:"http://localhost:8082/api/getlunbo",
success:res => {
console.log(res); // 到这里写完后在到data里面存到里面
// 判断一下 需要用到方法文档 API 界面交互反馈uni.showToast(OBJECT)
if(res.data.status !== 0){ // 意思打印请求数据看到的 res.data.status
return uni.showToast({
title:"获取数据失败",
})
}
// 否则 成功返回并存放到data数据里面
this.swipers = res.data.message /// message打印看到的
}
})
},
},
onLoad(){
this.getSwipers();
}
}
</script>
<style>
</style>
21. uniapp 获取轮播图的数据
Guess you like
Origin blog.csdn.net/m0_49714202/article/details/115840682
Recommended
Ranking