image.png
    index.vue 全部代码:

    1. <template>
    2. <view class='home'>
    3. <swiper indicator-dots circular>
    4. <swiper-item v-for='item in swipers' :key='item.id'>
    5. <image :src='item.img'></image> //v-bind可以用:表示
    6. </swiper-item>
    7. </swiper>
    8. </view>
    9. </template>
    10. <script>
    11. export default {
    12. data() {
    13. return {
    14. swipers:[]
    15. }
    16. },
    17. onLoad() { //监听页面加载
    18. this.getSwiper()
    19. },
    20. methods: {
    21. //获取轮播的数据
    22. // async getSwiper(){
    23. // console.log('获取轮播的数据')
    24. // const res = await uni.request({
    25. // url:'http://localhost:8082/api/getlunbo',
    26. // })
    27. // console.log(res.data)
    28. // }
    29. //获取轮播数据
    30. async getSwiper(){
    31. // console.log('获取轮播的数据')
    32. // uni.request({
    33. // url:'http://localhost:8082/api/getlunbo',
    34. // success:res=>{
    35. // console.log(res.data.message)
    36. // if(res.data.status !== 0){
    37. // return uni.showToast({
    38. // title:'获取数据失败'
    39. // })
    40. // }
    41. // this.swipers = res.data.message
    42. // }
    43. // })
    44. const res =await this.$myRequest({
    45. url:'/api/getlunbo'
    46. })
    47. this.swipers = res.data.message
    48. }
    49. }
    50. }
    51. </script>
    52. //scss 注意需要安装,否则会出现错误的
    53. <style lang="scss">
    54. .home{
    55. swiper{
    56. width:750rpx; //750rpx表示的是全屏的
    57. height: 380rpx; //表示一半
    58. image{
    59. height:100%;
    60. width:100%;
    61. }
    62. }
    63. }
    64. </style>