lushuncheng 6 anni fa
parent
commit
debff1cd44
2 ha cambiato i file con 44 aggiunte e 2 eliminazioni
  1. 42 0
      pages/salary/_id.vue
  2. 2 2
      plugins/nuxtAxios.js

+ 42 - 0
pages/salary/_id.vue

@@ -126,6 +126,48 @@
         ]
       };
     },
+      async asyncData ({ $axios, req, res }) {
+          // 请检查您是否在服务器端
+          // 使用 req 和 res
+          console.log(req)
+          if (process.server) {
+              const path = req.url
+              const cityJob = path.split('/')[2]
+              const city = cityJob.split('-')[0]
+              const job = cityJob.split('-')[1]
+              let params = {
+                  job: job,
+                  city: city
+              };
+              let res = await $axios.$post("/api/salary/search_info", params);
+
+              const jobList = res.data.jobSort || [];
+              const experience = res.data.experience || [];
+
+
+              for (let i = 0; i < jobList.length; i++) {
+                  jobList[i].salary = parseInt(jobList[i].salary);
+              }
+              for (let i = 0; i < experience.length; i++) {
+                  experience[i].salary = parseInt(experience[i].salary);
+              }
+              return {
+                  host: req.headers.host,
+                  job: res.data.info.job,
+                  city: res.data.info.city,
+                  avg_salary: res.data.info.avg_salary,
+                  max_salary: res.data.info.max_salary,
+                  min_salary: res.data.info.min_salary,
+                  jobList: jobList,
+                  experience: experience,
+                  allCitySalary: res.data.allCitySalary || [],
+                  salaryRange: res.data.salaryRange || [],
+                  screenWidth: 1366,
+              }
+          }
+
+          return {}
+      },
     data() {
       return {
         screenWidth: 0,

+ 2 - 2
plugins/nuxtAxios.js

@@ -9,8 +9,8 @@ export default function({ $axios, redirect, req, ...args }) {
 			config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
 		}
 		console.log('Before, making request to ', config.url, config.baseURL);
-		const referer = config.headers.host || (config.headers.common && config.headers.common.referer);
-		const baseUrl = /https?/.test(referer) ? referer : 'https://' + referer;
+		const referer = req.headers.host || (config.headers.common && config.headers.common.referer);
+		const baseUrl = /https?/.test(referer) ? referer : 'http://' + referer;
 		const url = config.url;
 		// if (referer && !(/https?/.test(url))) {
 		if (typeof window === 'undefined') {