After the cordova is packaged into apk, how to set up the axios asynchronous request?

the asynchronous request code in a general vue project is as follows:

invoke asynchronous request:

axios.get("/api/index.json").then()
The configuration code in

config/index.js is as follows:

proxyTable: {
  "/api": {
    target: "http://23.8.32.xxx",
    pathRewrite: {
      "^/api": "/static/mock"
    }
  }
},

npm run dev the data is accessible in the browser.

but packaged as apk , we can access the page through cordova serve android , and then access the page through http://localhost:8000/android/www/index.html-sharp/ in the browser (just like seeing the page on a mobile phone). The corresponding asynchronous request becomes http://localhost:8000/android/www/api/index.json, and this request returns 404 . So how do we modify the code that calls the asynchronous request above and the code related to the configuration of the asynchronous request ?


proxyTable takes effect only in development mode. Through cordova serve android , you are accessing the index.html file used in the packaged production environment, so the proxy is not valid.
request that url can directly write the absolute address on the server and the correct address will be accessed.
if the development environment and production environment want to request different addresses, you can make your own judgment.

Menu