From 2228c66b078516f09d7d31c46204c6b7a4d061ba Mon Sep 17 00:00:00 2001 From: "jqtmviyu@gmail.com" Date: Sun, 21 Feb 2021 20:39:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AE=E6=92=AD=E5=9B=BE=E4=BC=98=E5=8C=96:?= =?UTF-8?q?=201.http=E8=AF=B7=E6=B1=82=E4=BC=98=E5=8C=96=202.=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=86=99=E5=88=B0methods=E8=B0=83=E7=94=A8=203.=20?= =?UTF-8?q?=E7=94=A8async=20await=E5=90=8C=E6=AD=A5=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index/index.vue | 48 +++++++++++---------------------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index fc0ae77..14c847a 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -7,7 +7,7 @@ - + @@ -17,47 +17,25 @@ export default { data() { return { - list: [ - // { - // image: 'https://cdn.uviewui.com/uview/swiper/1.jpg', - // title: '昨夜星辰昨夜风,画楼西畔桂堂东' - // }, - // { - // image: 'https://cdn.uviewui.com/uview/swiper/2.jpg', - // title: '身无彩凤双飞翼,心有灵犀一点通' - // }, - // { - // image: 'https://cdn.uviewui.com/uview/swiper/3.jpg', - // title: '谁念西风独自凉,萧萧黄叶闭疏窗,沉思往事立残阳' - // } - ] + swiperList: [] } }, // 页面生命周期 onLoad() { - uni.request({ - url:'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata', - }) - // .then(console.log) - //promise会传递参数给它 - .then(res=>{ - const message = res[1].data.message - // 方法1 - /* - message.forEach(v => { - v.image = v.image_src - }) - this.list = [...message] - */ - //方法2 - this.list = message.map(v=>({ - ...v,image:v.image_src - })) - //箭头函数后面跟({}), 就不会把大括号解析成语句块的开始, 而是对象的一部分,()包起来, 相当于return - }) + this.getSwiper(); }, methods: { + // getSwiper(){ + // this.$u.get("/home/swiperdata") + // .then(res=>{ + // this.swiperList = res.message.map(v=>({...v,image:v.image_src})) + // }) + // } + async getSwiper(){ + const { message } = await this.$u.get("/home/swiperdata") + this.swiperList = message.map(v=>({...v,image:v.image_src})) + } } }