categoryList.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <view class="tabs-nav-warp">
  3. <scroll-view class="tabs-nav" scroll-x="true">
  4. <view class="ul">
  5. <view class="li" :class="{'on':activeTab===0}" @click="tabChange(0)">首页</view>
  6. <view class="li" :class="{'on':activeTab===index+1}" v-for="(item,index) in categoryList" :key="index" @click="tabChange(index+1,item.classifyId)">
  7. {{item.classifyName}}
  8. </view>
  9. </view>
  10. </scroll-view>
  11. </view>
  12. </template>
  13. <script>
  14. const NET = require('@/utils/request')
  15. const API = require('@/config/api')
  16. export default {
  17. name: "categoryList",
  18. data () {
  19. return {
  20. activeTab: 0,
  21. categoryList: []
  22. }
  23. },
  24. mounted () {
  25. this.getCategoryData();
  26. },
  27. methods:{
  28. tabChange (index, id) {
  29. this.activeTab = index
  30. this.$emit('tabChange', index, id)
  31. },
  32. getCategoryData(){
  33. uni.showLoading({
  34. title:'加载中...'
  35. })
  36. NET.request(API.FindCategoryListByDepth, {
  37. }, 'GET').then(res => {
  38. this.categoryList = res.data
  39. uni.hideLoading()
  40. }).catch(res => {
  41. uni.hideLoading()
  42. })
  43. }
  44. }
  45. }
  46. </script>
  47. <style lang="scss" scoped>
  48. .tabs-nav-warp{
  49. //margin-top: 20rpx;
  50. padding:0 30rpx;
  51. .tabs-nav{
  52. .ul{
  53. display: flex;
  54. .li{
  55. flex: 1 0 auto;
  56. margin-left: 36rpx;
  57. font-size: 30rpx;
  58. color: #999999;
  59. position: relative;
  60. padding: 18rpx 0;
  61. box-sizing: border-box;
  62. &:first-child{
  63. margin-left: 0;
  64. }
  65. &.on{
  66. &:after{
  67. content: '';
  68. width: 100%;
  69. height: 4rpx;
  70. background: #C5AA7B;
  71. position: absolute;
  72. left: 0;
  73. bottom: 0;
  74. }
  75. font-weight:bold;
  76. }
  77. }
  78. }
  79. }
  80. }
  81. </style>