_type.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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"></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 qs from "qs";
  11. import SolutionIndex from "@/pages/solution/index";
  12. const pageLimit = 5;
  13. export default {
  14. name: "typeNewsPage",
  15. props:[],
  16. async asyncData(ctx){
  17. // ctx.searchProduct();
  18. const queryData = {};
  19. // console.log(ctx)
  20. queryData['key']=ctx.key;
  21. queryData['type']=ctx.params.type?ctx.params.type:'all';
  22. queryData['page']=1;
  23. queryData['limit']=pageLimit;
  24. // 获取数据
  25. let url = 'http://szhfy.com.cn/api/searchNews.php';
  26. let [err,res] = await handle(axios.post(
  27. url,
  28. qs.stringify(queryData)
  29. ));
  30. if(err){
  31. console.log(err);
  32. return {};
  33. }
  34. let result = res.data;
  35. if(result.rcode === 1){
  36. return {solutions:result.data}
  37. }else{
  38. console.error(result.msg);
  39. console.log(result);
  40. return {solutions:[]}
  41. }
  42. },
  43. data(){
  44. return {
  45. type: 'all',
  46. solutions: []
  47. }
  48. },
  49. beforeMount() {
  50. // console.log('动态页面执行');
  51. this.type = this.$route.params.type?this.$route.params.type:'all';
  52. // console.log(this.type);
  53. },
  54. components:{
  55. SolutionIndex,
  56. }
  57. }
  58. </script>
  59. <style scoped>
  60. </style>