報錯
<template> <view > 首頁 </view> </template> <script> export default { data() { return { title: 'Hello', swipers:[] } }, onLoad() { this.getSwipers() }, methods: { //獲取輪播圖的數據 getSwipers(){ console.log("獲取輪播") uni.request({ url:"https://www.baidu.com/", success:function(res){ console.log("添加數組") this.swipers.push("static/lunbo/bg1.jpg"); this.swipers.push("static/lunbo/hx1.jpg"); this.swipers.push("static/lunbo/hx2.jpg"); }, }) } } } </script> <style> </style>
正常
<template> <view > 首頁 </view> </template> <script> export default { data() { return { title: 'Hello', swipers:[] } }, onLoad() { this.getSwipers() }, methods: { //獲取輪播圖的數據 getSwipers(){ var thi=this console.log("獲取輪播") uni.request({ url:"https://www.baidu.com/", success:function(res){ console.log("添加數組") thi.swipers.push("static/lunbo/bg1.jpg"); thi.swipers.push("static/lunbo/hx1.jpg"); thi.swipers.push("static/lunbo/hx2.jpg"); }, }) } } } </script> <style> </style>
正常2
<template> <view > 首頁 </view> </template> <script> export default { data() { return { title: 'Hello', swipers:[] } }, onLoad() { this.getSwipers() }, methods: { //獲取輪播圖的數據 getSwipers(){ console.log("獲取輪播") uni.request({ url:"https://www.baidu.com/", success:res=>{ console.log("添加數組") this.swipers.push("static/lunbo/bg1.jpg"); this.swipers.push("static/lunbo/hx1.jpg"); this.swipers.push("static/lunbo/hx2.jpg"); }, }) } } } </script> <style> </style>