index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div class="client-newsInfor-page">
  3. <div :style="{backgroundImage: 'url(' + bannerDefault + ')'}" class="client-banner-box"></div>
  4. <!-- 新闻资讯 -->
  5. <h4 class="client-title">新闻中心</h4>
  6. <div class="client-container newsInfor-content-box">
  7. <ul class="newsInfor-content-ul" style="width:100%">
  8. <template >
  9. <new-list
  10. v-for="(item,index) in newsList"
  11. :newsData="item"
  12. :key="index"></new-list>
  13. </template>
  14. </ul>
  15. <div class="client-el-pagination">
  16. <el-pagination
  17. background
  18. small
  19. layout="prev, pager, next"
  20. @current-change="handleCurrentChange"
  21. :current-page.sync="currentPage"
  22. :page-size="pageSize"
  23. :total="totalLists">
  24. </el-pagination>
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import NewList from '~/components/news/NewsList';
  31. const defaultNewsClassifyId = 0;
  32. export default {
  33. name: 'news',
  34. layout: 'templateB',
  35. components: {
  36. NewList
  37. },
  38. async asyncData({ $axios, store }) {
  39. // 设置选中菜单
  40. store.commit('setActiveNav', '/news');
  41. try {
  42. const url2 = '/common/client/web/news/list';
  43. const opt = {
  44. page: 1,
  45. size: 10,
  46. };
  47. const res2 = await $axios.post(url2, opt);
  48. const { data: { data: data2 } } = res2;
  49. return {
  50. newsList: data2.data || [],
  51. totalLists: data2.total || defaultNewsClassifyId,
  52. };
  53. } catch (e) {
  54. return {
  55. newsList: [],
  56. totalLists: 0,
  57. };
  58. }
  59. },
  60. data() {
  61. return {
  62. clicked: 0,
  63. newsClassifyId: null,
  64. homeNewsClassify: [],
  65. totalLists: 0,
  66. currentPage: 1,
  67. pageSize: 10,
  68. // 新闻数据
  69. newsList: [],
  70. activeIndex: 1,
  71. // banner图
  72. bannerDefault: require(`~/static/images/website/banner/cx-banner-xwzx.png`),
  73. };
  74. },
  75. head(){
  76. return {
  77. title: '家政学',
  78. }
  79. },
  80. methods: {
  81. clickBanner(data){
  82. if(data){
  83. window.open(data)
  84. }
  85. },
  86. handleCurrentChange(val) {
  87. this.currentPage = val;
  88. this.getMessage();
  89. },
  90. async getMessage() {
  91. let opt = {
  92. page: this.currentPage,
  93. size: this.pageSize,
  94. };
  95. const url2 = '/common/client/web/news/list';
  96. const res2 = await this.$axios.post(url2, opt);
  97. this.newsList = res2.data.data;
  98. this.totalLists = res2.data.total || defaultNewsClassifyId;
  99. },
  100. btnClick(data, index) {
  101. this.activeIndex = index;
  102. console.log(data);
  103. this.currentPage = 1;
  104. this.getMessage();
  105. },
  106. },
  107. mounted() {
  108. }
  109. };
  110. </script>
  111. <style>
  112. </style>