_type.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <!-- <product-index :p-type="type" :p-product="products"/>-->
  3. <!-- <solution-index :p-type="type" :p-solution="solutions"></solution-index>-->
  4. <news-index :p-type="type" :p-news="solutions" :p-page-data="basePageData"></news-index>
  5. </template>
  6. <script>
  7. import productIndex from '@/pages/product/index.vue'
  8. import {handle} from "~/until/handle";
  9. import axios from "axios";
  10. import SolutionIndex from "@/pages/solution/index";
  11. import {apiMap, baseUrl} from "~/map/apiMap";
  12. export default {
  13. name: "typeNewsPage",
  14. props:[],
  15. async asyncData(ctx){
  16. // 获取数据
  17. let url = baseUrl + apiMap.searchNews.path;
  18. let type = ctx.params.type?ctx.params.type:'all';
  19. url += `?type=${type}&p=1`
  20. let [err,res] = await handle(axios.get( url));
  21. if(err){
  22. console.log(err);
  23. return {};
  24. }
  25. let result = res.data;
  26. if(result.code === 1){
  27. let pageData = {
  28. limit: result.limit,
  29. page: result.page,
  30. total: result.total,
  31. count: result.count,
  32. }
  33. return {
  34. news: result.data,
  35. basePageData: pageData,
  36. }
  37. }else{
  38. return {products:[]}
  39. }
  40. },
  41. data(){
  42. return {
  43. type: 'all',
  44. basePageData: {},
  45. news: []
  46. }
  47. },
  48. beforeMount() {
  49. this.type = this.$route.params.type?this.$route.params.type:'all';
  50. },
  51. components:{
  52. SolutionIndex,
  53. }
  54. }
  55. </script>
  56. <style scoped>
  57. </style>