ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# vuecli3 跨域 ### vurecli3 跨域问题 1。 首先在根目录创建vue.config.js文件 ``` <pre class="calibre13">``` module<span class="token1">.</span>exports <span class="token">=</span> <span class="token1">{</span> devServer<span class="token1">:</span> <span class="token1">{</span> host<span class="token1">:</span> <span class="token4">'localhost'</span><span class="token1">,</span> port<span class="token1">:</span> <span class="token4">'8081'</span><span class="token1">,</span> https<span class="token1">:</span> <span class="token5">false</span><span class="token1">,</span> hotOnly<span class="token1">:</span> <span class="token5">false</span><span class="token1">,</span> proxy<span class="token1">:</span> <span class="token1">{</span> <span class="token4">'/api'</span><span class="token1">:</span> <span class="token1">{</span> target<span class="token1">:</span> <span class="token4">'http://localhost:8080'</span><span class="token1">,</span> <span class="token6">// API服务器的地址</span> ws<span class="token1">:</span> <span class="token5">true</span><span class="token1">,</span> <span class="token6">// 代理websockets</span> changeOrigin<span class="token1">:</span> <span class="token5">true</span><span class="token1">,</span> <span class="token6">// 虚拟的站点需要更管origin</span> pathRewrite<span class="token1">:</span> <span class="token1">{</span> <span class="token6">// 重写路径</span> <span class="token4">'^/api'</span><span class="token1">:</span> <span class="token4">''</span> <span class="token1">}</span> <span class="token1">}</span> <span class="token1">}</span> <span class="token1">}</span> <span class="token1">}</span> ``` ``` ``` <pre class="calibre14">``` <span class="token2">import</span> Vue <span class="token2">from</span> <span class="token4">'vue'</span> <span class="token2">import</span> App <span class="token2">from</span> <span class="token4">'./App.vue'</span> <span class="token2">import</span> router <span class="token2">from</span> <span class="token4">'./router'</span> <span class="token2">import</span> store <span class="token2">from</span> <span class="token4">'./store'</span> <span class="token2">import</span> axios <span class="token2">from</span> <span class="token4">'axios'</span> Vue<span class="token1">.</span>config<span class="token1">.</span>productionTip <span class="token">=</span> <span class="token5">false</span> <span class="token2">new</span> <span class="token3">Vue</span><span class="token1">(</span><span class="token1">{</span> router<span class="token1">,</span> store<span class="token1">,</span> render<span class="token1">:</span> h <span class="token">=></span> <span class="token3">h</span><span class="token1">(</span>App<span class="token1">)</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">$mount</span><span class="token1">(</span><span class="token4">'#app'</span><span class="token1">)</span> <span class="token6">// 创建axios实例</span> <span class="token2">const</span> instance <span class="token">=</span> axios<span class="token1">.</span><span class="token3">create</span><span class="token1">(</span><span class="token1">{</span> <span class="token6">// baseURL: 'api',</span> timeout<span class="token1">:</span> <span class="token5">5000</span> <span class="token1">}</span><span class="token1">)</span> <span class="token2">const</span> param <span class="token">=</span> <span class="token2">new</span> <span class="token3">URLSearchParams</span><span class="token1">(</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'levyId'</span><span class="token1">,</span> <span class="token4">'34156'</span><span class="token1">)</span> <span class="token6">// http://mer.bjlinggong.com/trans-business/clientBusiness/common.do</span> <span class="token6">// http://api.youfupingtai.com/pctrans-business/clientBusiness/common.do</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'daxiongUrl'</span><span class="token1">,</span> <span class="token4">'http://39.98.220.12:8280/trans-business/clientBusiness/common.do'</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'priKey'</span><span class="token1">,</span> <span class="token4">'MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAI5BV4LKgpuZZs6NKRFlglgIPz496JiQmhAQ+ux23KeC5G3WzYx3aLbSJ3Wcy+CHDzPwqP+txReLjgz8JmsU40g2XhEzGrP4tpcOXrhSO6fV/3ydaIX4nOjqljCUH5Iox3+laP/zLjsOSAWi9ZaeXO4KZ1YvmiUNkq14uG1i5i59AgMBAAECgYBla/a9fC6US1F98CyYh5vfsbmNYcwkgewlikWsM65sC6lbGmugOz5AIiMZ+nltEj3nlSyYZccAW3Iild+6NsE3mSDiuCTjZRrW5L8eG8+Tr7If8q3B1g+Ylw6+Djsuc8vG0nk3qqEoWr9jU0SMi1xaFrnV00LqZyMlin7Fm6uEzQJBAM0YmhSL5JwPEzMiKyf5gNclAIzi0FXBAUXhebDy3YmLl1nGy94DrX5Y/oTayAoI42YT4ftbYCjvTFAQWawtJOsCQQCxj/Tw/J61qw9Vios7Pp8HzpS8qK8LzIANBvUAXsXuC9aCehHq1P1XszWKurmg88Dmw1y6A1uuoq97LXFnycA3AkEAo/jDVyHxCAPVadAriK4ln9xpcDn2Llk8V05JKHtDOzBrNM+HNlziXF1yP21a+QraI0ZKKdeILbID5Q7tYoZFOQJARlqCs8V0YQjhL4SQfC3otyAsIMA5c1RY3FCIXNgwVoyMNvCFDuXLZ6dTLJ+lk1dhdE2t/On9tqkxHH458+SlawJBAK1b9kR96fvTyyjCTd2KMjKAYygxFlcJ4dnJcaIFRgFazDwH/KVfyswDe3nTbVT4fKhS5cKsrEYncspPelyfJsk='</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'pubKey'</span><span class="token1">,</span> <span class="token4">'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCXFtJNcCv9X+pfOz+jy4WO+7KC0tdtDGfW/XrJOFn6mTR/TpJrsLzwssTyj0hDfUla1xDCbAWlUEkzb64jsPKk9WACupLOOrnEy7NuG0O5jg36UXle+m5/uDm8B/KGV9BQmEt+EOIbl2IzNYS4GflkbCTtkbzMc+DXetl3IHM1+wIDAQAB'</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'charset'</span><span class="token1">,</span> <span class="token4">'UTF-8'</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'apiKey'</span><span class="token1">,</span> <span class="token4">'73E5C9C6D6A1155EF5C78B4282DADBCE'</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'merId'</span><span class="token1">,</span> <span class="token4">'89900000610116178476'</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'reqId'</span><span class="token1">,</span> <span class="token4">'60181623910710169'</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'startDate'</span><span class="token1">,</span> <span class="token4">'2021-06-01 00:00:00'</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'endDate'</span><span class="token1">,</span> <span class="token4">'2021-06-31 00:00:00'</span><span class="token1">)</span> <span class="token3">instance</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span> <span class="token4">'/api/sbh/querySbhTransactionFlow'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'post'</span><span class="token1">,</span> data<span class="token1">:</span> param <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">then</span><span class="token1">(</span>res <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>res<span class="token1">)</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token2">catch</span><span class="token1">(</span>err <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>err<span class="token1">)</span> <span class="token1">}</span><span class="token1">)</span> ``` ```