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.title}}</view>
    5. </scroll-view>
    6. </view>
    7. </template>
    8. <script>
    9. export default {
    10. data() {
    11. return {
    12. cates:[],
    13. active:0
    14. };
    15. },
    16. methods:{
    17. async getPicsCate(){
    18. const res = await this.$myRequest({
    19. url:'/api/getimgcategory'
    20. })
    21. this.cates = res.data.message
    22. },
    23. leftClickHandle(index){ //点击一下就变成高亮
    24. this.active = index
    25. }
    26. },
    27. onLoad(){
    28. this.getPicsCate()
    29. }
    30. }
    31. </script>
    32. <style lang="scss">
    33. page{
    34. height:100%;
    35. }
    36. .pics{
    37. height:100%;
    38. .left{
    39. width:200rpx;
    40. height:100%;
    41. border-right:1px solid #eee;
    42. view{
    43. height:60px;
    44. line-height:60px;
    45. color:#333;
    46. text-align: center;
    47. font-size:35rpx;
    48. border-top:1px solid #eee;
    49. }
    50. .active{
    51. background: $shop-color;
    52. color:#fff;
    53. }
    54. }
    55. }
    56. </style>

    image.png
    一定要注意函数绑定以及动态绑定。data数据的应用