首页 > 其他分享 >解决跨域问题:配置代理

解决跨域问题:配置代理

时间:2022-11-29 11:44:07浏览次数:38  
标签:vue 跨域 配置 代理 api target defineConfig

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave:false,
  //代理跨域
  devServer:{
    proxy:{
      '/api':{
        target:'http:',
        // pathRewrite:{'^/api':''}
      }
    }
  }
})
target 为你后端接口地址

此文件为vue.config.js
通过配置代理 vue自带的服务器会自动向接口服务器请求 从而解决跨域问题

标签:vue,跨域,配置,代理,api,target,defineConfig
From: https://www.cnblogs.com/xiaobaizitaibai/p/16934997.html

相关文章

  • linux 下安装以及配置postgresql
    1、准备好资源 下载 PostgreSQL官网下载地址  ​​https://www.postgresql.org/ftp/source/v12.2/​​​  我这里下载的是 ​​postgresql-12.2.tar.gz​​ 压缩包......
  • vuecli3配置文件路径别名
    vue.config.js文件中module.exports={configureWebpack:{resolve:{alias:{'assets':'@/assets','common':'@/common',......
  • vue3-vite下tailwindcss安装与配置
    初始化TailwindCSS安装Tailwind以及其它依赖项:npminstall-Dtailwindcss@latestpostcss@latestautoprefixer@latest一、创建您的配置文件接下来,生成您的 t......
  • vue3-vite下配置postcss-pxtorem进行移动端适配
    如果使用Vue进行移动端页面的开发,需要对不同机型的宽高进行适配。最常用的方法是使用amfe-flexable和postcss-pxtorem这两个插件来帮助进行适配。amfe-flexableamfe-flex......
  • 转:PKG_CONFIG_PATH 环境变量配置
    摘自:https://www.fujieace.com/kali-linux/pkg_config_path.htmlhttps://www.cnblogs.com/LiuYanYGZ/p/14198977.html由于最近在瞎搞KaliLinuxNetHunter,需要用上“p......
  • Nginx反向代理NFS
    作者:独笔孤行官网:​​​http://anyamaze.com​​公众号:云实战前言Nginx是一个轻量级、高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。其特点是占有内......
  • opensuse nginx+mono 2.8支持aspx环境的配置
    nginx(发音同enginex)是一款轻量级的Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like协议下发行。由俄罗斯的程序设计师IgorS......
  • SpringBoot 2.4.0版本后解决跨域问题
    packagecom.atguigu.gulimall.gateway.config;importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Configuration;impor......
  • 【Vue】vite + ts 配置别名
    1.vite.config.tsimport{defineConfig}from'vite'importvuefrom'@vitejs/plugin-vue'import{resolve}from'path'function_resolve(dir:string){returnreso......
  • CentOS 7 NTP服务端和客户端详细配置
    1.安装NTP1.1yum安装yum-yinstallntp1.2开机自启#设置开机启动chkconfigntpdonsystemctlenablentpdsystemctlstartntpdsystemctlstatusntpdsystemctldaemon-r......