实现右边数据的加载渲染: pic.vue

    1. <template>
    2. <view class='pics'>
    3. <scroll-view class='left' scroll-y>
    4. <view :class="active === index?'active':''" v-for='(item,index) in cates' :key='item.id' @click="leftClickHandle(index,item.id)">{{item.title}}</view>
    5. </scroll-view>
    6. <scroll-view class='right' scroll-y>
    7. <view class='item' v-for='item in secondData' :key='item.id'>
    8. <image :src='item.img_url'></image>
    9. <text>{{item.title}}</text>
    10. </view>
    11. <text v-if='secondData.length === 0'>暂无数据</text>
    12. </scroll-view>
    13. </view>
    14. </template>
    15. <script>
    16. export default {
    17. data() {
    18. return {
    19. cates:[],
    20. active:0,
    21. secondData:[]
    22. };
    23. },
    24. methods:{
    25. async getPicsCate(){
    26. const res = await this.$myRequest({
    27. url:'/api/getimgcategory'
    28. })
    29. this.cates = res.data.message
    30. this.leftClickHandle(0,this.cates[0][id])
    31. },
    32. async leftClickHandle(index,id){ //点击一下就变成高亮
    33. this.active = index
    34. //console.log(id)
    35. //获取右侧的数据
    36. const res = await this.$myRequest({
    37. url:'/api/getimages/'+id
    38. })
    39. this.secondData = res.data.message
    40. }
    41. },
    42. onLoad(){
    43. this.getPicsCate()
    44. }
    45. }
    46. </script>
    47. <style lang="scss">
    48. page{
    49. height:100%;
    50. }
    51. .pics{
    52. height:100%;
    53. display: flex;
    54. .left{
    55. width:200rpx;
    56. height:100%;
    57. border-right:1px solid #eee;
    58. view{
    59. height:60px;
    60. line-height:60px;
    61. color:#333;
    62. text-align: center;
    63. font-size:35rpx;
    64. border-top:1px solid #eee;
    65. }
    66. .active{
    67. background: $shop-color;
    68. color:#fff;
    69. }
    70. }
    71. .right{
    72. height:100%;
    73. width:530rpx;
    74. margin:20rpx auto;
    75. .item{
    76. image{
    77. width:520rpx;
    78. height:520rpx;
    79. border-radius: 5px;
    80. }
    81. text{
    82. font-size: 30rpx;
    83. line-height: 50rpx;
    84. }
    85. }
    86. }
    87. }
    88. </style>

    image.png