1. <template>
    2. <view>
    3. 首页
    4. </view>
    5. </template>
    6. <script>
    7. export default {
    8. data() {
    9. return {
    10. swipers:[]
    11. }
    12. },
    13. onLoad() { //监听页面加载
    14. this.getSwiper()
    15. },
    16. methods: {
    17. //获取轮播的数据
    18. getSwiper(){
    19. console.log('获取轮播的数据')
    20. uni.request({
    21. url:'http://localhost:8082/api/getlunbo',
    22. success:res=>{
    23. console.log(res.data.message)
    24. if(res.data.status !== 0){
    25. return uni.showToast({
    26. title:'获取数据失败'
    27. })
    28. }
    29. this.swipers = res.data.message
    30. }
    31. })
    32. }
    33. }
    34. }
    35. </script>
    36. <style>
    37. </style>

    api获取数据,利用带了uni.request