Preface:
There are many cross-domain solutions. Since we have used Vue, we will use the cross-domain solutions provided by vue.
Solution:
1. Modify
import axios from 'axios' export var baseurl = '/api' /** * Get request */ export function get(url, callback){ ('Test get request') (baseurl+url) .then(function (response) { (response) callback(,true) }) .catch(function (error) { (error) callback(null,false) }) } export default { get }
2. Modify
'use strict' // Template version: 1.3.1 // see /webpack for documentation. const path = require('path') = { dev: { // Paths assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: { '/api': { target: 'http://127.0.0.1:8088',//Set the interface domain name and port number you call. Don't forget to add http. changeOrigin: true, pathRewrite: { '^/api': 'http://127.0.0.1:8088'//This is understood as using '/api' instead of the address in the target. In the later component, we use api directly instead of when we drop the interface. For example, if I want to call 'http://40.00.100.100:3002/user/add', just write '/api/user/add' } } }, // Various Dev Server settings host: 'localhost', // can be overwritten by port: 8090, // can be overwritten by , if port is in use, a free one will be determined autoOpenBrowser: false, errorOverlay: true, notifyOnErrors: true, poll: false, // /configuration/dev-server/#devserver-watchoptions- /** * Source Maps */ // /configuration/devtool/#development devtool: 'cheap-module-eval-source-map', // If you have problems debugging vue-files in devtools, // set this to false - it *may* help // /en/#cachebusting cacheBusting: true, cssSourceMap: true }, build: { // Template for index: (__dirname, '../dist/'), // Paths assetsRoot: (__dirname, '../dist'), assetsSubDirectory: 'static', assetsPublicPath: '/', /** * Source Maps */ productionSourceMap: true, // /configuration/devtool/#production devtool: '#source-map', // Gzip off by default as many popular static hosts such as // Surge or Netlify already gzip all static assets for you. // Before setting to `true`, make sure to: // npm install --save-dev compression-webpack-plugin productionGzip: false, productionGzipExtensions: ['js', 'css'], // Run the build command with an extra argument to // View the bundle analyzer report after build finishes: // `npm run build --report` // Set to `true` or `false` to always turn it on or of bundleAnalyzerReport: .npm_config_report } }
proxyTable: { '/api' : { target: 'http://127.0.0.1:8088' , //Set the interface domain name and port number you call Don't forget to add httpchangeOrigin: true , pathRewrite: { '^/api' : 'http://127.0.0.1:8088' //This is understood as using '/api' instead of the address in the target. In the later component, we use api directly instead of when we drop the interface. For example, if I want to call 'http://40.00.100.100:3002/user/add', just write '/api/user/add'} } },
Summarize
The above is the cross-domain problem of Vue introduced by the editor to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!