homeTabs.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <script>
  2. import BlockList from '../../blocks/block_list.vue'
  3. import Api from "../../../lib/api.js"
  4. import Search from "../../blocks/search"
  5. import {XHeader, Tab, TabItem, Divider, Flexbox, FlexboxItem} from 'vux'
  6. export default {
  7. created() {
  8. let _self = this;
  9. let arr = this.$route.path.split("\/");
  10. this.current_id = arr [arr.length - 1];
  11. this.$http.jsonp(Api.homeTabs(),).then(function (res) {
  12. _self.tabs = res.body.datas.tabs;
  13. })
  14. },
  15. data(){
  16. return {
  17. tabs: null,
  18. current_id: 0,
  19. }
  20. },
  21. methods: {
  22. isSelected(item, special_id){
  23. return item.special_id == special_id;
  24. }
  25. }
  26. ,
  27. render(createElement)
  28. {
  29. if (!this.tabs)
  30. return
  31. let nativeClickHandler = (index, item) => {
  32. this.current_id = item.special_id;
  33. this.$router.push({path: "" + this.current_id})
  34. }
  35. //tab
  36. const top_tabs = this.tabs.map((item, index) => {
  37. return <TabItem class="tab_item" selected={this.isSelected(item, this.current_id)}
  38. nativeOnClick={ () => nativeClickHandler(index, item)}>{ item.name}</TabItem>
  39. })
  40. return (
  41. <div>
  42. <Search isScroll={this.isScroll}></Search>
  43. <div>
  44. <div class="list_tab" style = {{position:'fixed'}}>
  45. <Tab style={{width: 150 * this.tabs.length + "px",background:"#fff"}}
  46. customBarWidth="150px">{top_tabs}</Tab>
  47. </div>
  48. </div>
  49. <div class="list_container">
  50. <router-view></router-view>
  51. </div>
  52. </div>
  53. )
  54. }
  55. }
  56. </script>
  57. <style scoped>
  58. img {
  59. vertical-align: bottom;
  60. width: 100%;
  61. height: auto;
  62. display: block;
  63. }
  64. .list_tab {
  65. position: relative;
  66. z-index: 1000;
  67. width: 100%;
  68. margin-top: 83px;
  69. overflow-y : auto;
  70. -webkit-box-sizing : border-box;
  71. -webkit-overflow-scrolling: touch;
  72. background: #fff;
  73. }
  74. .list_tab::-webkit-scrollbar {
  75. display: none;
  76. }
  77. .list_container {
  78. padding-top: 170px;
  79. padding-bottom: 101px;
  80. }
  81. .tab_item {
  82. overflow: hidden;
  83. text-overflow: ellipsis;
  84. white-space: nowrap;
  85. }
  86. .list_hide {
  87. display: none;
  88. }
  89. </style>