Vue跨域請求配置,避免再次踩坑

1.配置config->index.js
	// dev: 中
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
      '/api': {		// 這個api爲自定義的字符串,相當於'/api' == 'http://192.168.123.130:9979'
          target: 'http://192.168.123.130:9979',	// 需要跨域的地址以及端口名,後面不能帶/
          changeOrigin: true,		//是否跨域
          pathRewrite: {
              '^/api': '/'		//這裏相當於用/代替target中的地址,使用時get('/api/login')
          }
      }
    },
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章