Vue-resource cross-domain problem

I practiced what vue did during the project, so I used the third-party interface. Using proxies in local testing can solve cross-domain problems, as follows

proxyTable: {
    "/api": {  //"/api""https://zapi.tourzj.com" 
    target: "https://zapi.tourzj.com", // 
    changeOrigin: true, // 
    pathRewrite: { 
      "^/api": "https://zapi.tourzj.com" // 
      }
    }
},

but there is a cross-domain problem when uploading to its own server. Baidu says that it defines a global js,. How do you define it? Do you want to refer to it on each page after it is defined?

Nov.29,2021

Local development is done with the agent in webpack-dev-server , but when you produce a package, you must use nginx to forward it, or write a node (server language is fine) as the middle layer ~


use axios. Officially recommended, and cross-domain problems are usually solved by setting up a proxy or setting cors in the background to achieve cross-domain


. The method is as follows:
defines a variable to be mounted on Vue, written as follows: Vue.prototype.API_PROXY =' https://bird.ioliu.cn/v1/?url=';
then write the url address in the requested page as: var url = this.API_PROXY +' http://www.xxx.com';
last axios.get (url). Then (res= > {})

Menu