navs.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div class="list-info">
  3. <div class="title">
  4. <h4>园区快讯</h4>
  5. </div>
  6. <div class="list">
  7. <ul class="list-unstyled">
  8. <li v-for="(item, key) in listData" @mouseenter="item.activeImg = true" @mouseleave="item.activeImg = false" :class="{active: item.active}" @click="setActive(key)">
  9. <img :src="item.activeImg || item.active ? item.nt_activeicon : item.nt_icon">
  10. <span v-text="item.nt_name">12</span>
  11. </li>
  12. </ul>
  13. </div>
  14. </div>
  15. </template>
  16. <script>
  17. export default {
  18. name: 'NavsView',
  19. data () {
  20. return {
  21. listData: [],
  22. page: 1,
  23. limit: 10
  24. }
  25. },
  26. created () {
  27. if (!this.$store.state.news.newType.data.list) return false
  28. let data = JSON.parse(JSON.stringify(this.$store.state.news.newType.data.list))
  29. if (this.$route.query.type) {
  30. for (let i = 0; i < data.length; i++) {
  31. this.$set(data[i], 'active', data[i].nt_name === this.$route.query.type)
  32. this.$set(data[i], 'activeImg', data[i].nt_name === this.$route.query.type)
  33. }
  34. } else {
  35. for (let i = 0; i < data.length; i++) {
  36. this.$set(data[i], 'active', i === 0)
  37. this.$set(data[i], 'activeImg', i === 0)
  38. }
  39. }
  40. this.$store.dispatch('loadNewsList', {page: this.page, limit: this.limit, type: this.$route.query.type ? this.$route.query.type : data[0].nt_name})
  41. this.listData = data
  42. },
  43. methods: {
  44. setActive(type) {
  45. for (let i = 0; i < this.listData.length; i++) {
  46. if (type === i) {
  47. this.listData[i].active = true
  48. this.$store.dispatch('loadNewsList', {page: this.page, limit: this.limit, type: this.listData[i].nt_name})
  49. this.$emit('loadStep', this.listData[i].nt_name)
  50. this.$router.push('/news' + (this.$route.query.type ? '?type=' + this.listData[i].nt_name : ''))
  51. } else {
  52. this.listData[i].active = false
  53. this.listData[i].activeImg = false
  54. }
  55. }
  56. }
  57. }
  58. }
  59. </script>
  60. <style scoped type="text/scss" lang="scss">
  61. .list-info{
  62. background: #fff;
  63. .title{
  64. padding-left:25px;
  65. border-bottom:2px solid #8d8d8d;
  66. h4{
  67. line-height: 45px;
  68. color:#8d8d8d;
  69. font-size: 16px;
  70. }
  71. }
  72. .list{
  73. padding:10px 0;
  74. ul{
  75. li{
  76. text-align: center;
  77. height:60px;
  78. line-height: 60px;
  79. &.active, &:hover{
  80. background: #f8f8f8;
  81. cursor:pointer;
  82. span{
  83. color:#46a9d4;
  84. }
  85. }
  86. img{
  87. margin-right:15px;
  88. width:20px;
  89. height:20px;
  90. vertical-align: middle;
  91. }
  92. span{
  93. font-size: 18px;
  94. color:#646464;
  95. }
  96. }
  97. }
  98. }
  99. }
  100. </style>