日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

Vue之通过代理设置跨域访问

發布時間:2024/4/17 vue 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Vue之通过代理设置跨域访问 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我們使用腳手架創建的項目,可以在config項目中看到 其中我們打開index.js文件 'use strict' // Template version: 1.3.1 // see http://vuejs-templates.github.io/webpack for documentation. const path = require('path')module.exports = {dev: {// PathsassetsSubDirectory: 'static',assetsPublicPath: '/',proxyTable: {'/api': {target: 'http://192.168.0.173:8080',changeOrigin:true,//允許跨域pathRewrite: {'^/api': '/api'}}},// Various Dev Server settingshost: '0.0.0.0', // 代理會映射到本地的一個ip地址。這里我們可以通過改成根基的ip地址或者0.0.0.0然后通過手機就可以看到項目port: 8080, // 這里是我們本地設置的一個端口號autoOpenBrowser: false,errorOverlay: true,notifyOnErrors: true,poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-/*** Source Maps*/// https://webpack.js.org/configuration/devtool/#developmentdevtool: 'cheap-module-eval-source-map',// If you have problems debugging vue-files in devtools,// set this to false - it *may* help// https://vue-loader.vuejs.org/en/options.html#cachebustingcacheBusting: true,cssSourceMap: true},build: {// Template for index.htmlindex: path.resolve(__dirname, '../dist/index.html'),// PathsassetsRoot: path.resolve(__dirname, '../dist'),assetsSubDirectory: 'static',assetsPublicPath: '/',/*** Source Maps*/productionSourceMap: true,// https://webpack.js.org/configuration/devtool/#productiondevtool: '#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-pluginproductionGzip: 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 off bundleAnalyzerReport: process.env.npm_config_report} } ? 其中proxyTable就是創建項目所自帶的代理,當我們運行dev的時候,就會通過訪問代理來間接訪問我們的api。只需要添加屬性changeOrigin:true 就可以實現跨域訪問。同時可以提高安全系數。也省去了我們自定義請求文件時,所添加的主域!

轉載于:https://www.cnblogs.com/bgwhite/p/9805502.html

總結

以上是生活随笔為你收集整理的Vue之通过代理设置跨域访问的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。