当前位置: 首页 > news >正文

闵行区网站建设公司龙岗建设局网站

闵行区网站建设公司,龙岗建设局网站,山西省住房城乡建设厅网站首页,给视频做特效的网站系列文章 C#底层库–记录日志帮助类 本文链接:https://blog.csdn.net/youcheng_ge/article/details/124187709 文章目录 系列文章前言一、技术介绍二、问题描述三、问题解决3.1 方法一:前端Vue修改3.2 方法二:后端允许Cors跨越访问 四、资源…

系列文章

C#底层库–记录日志帮助类
本文链接:https://blog.csdn.net/youcheng_ge/article/details/124187709

文章目录

  • 系列文章
  • 前言
  • 一、技术介绍
  • 二、问题描述
  • 三、问题解决
    • 3.1 方法一:前端Vue修改
    • 3.2 方法二:后端允许Cors跨越访问
  • 四、资源链接


前言

本专栏为【H5】,主要介绍前端知识点。
在这里插入图片描述

一、技术介绍

跨越介绍

二、问题描述

vue2与netcore webapi跨越问题解决
在这里插入图片描述

三、问题解决

3.1 方法一:前端Vue修改

配置代理转发,加URL拦截,转换成新的URL
vue.config.js文件,加一下代码:

    proxy:{'/api': { // api表示拦截以/api开头的请求路径target: 'http://localhost:5296/api', //跨域的域名changeOrigin:true,//是否开启跨域pathRewrite:{ '^/api':'' // 重写请求,把/api变为空字符}}}

3.2 方法二:后端允许Cors跨越访问

Program.cs文件

//配置跨域
builder.Services.AddCors(c =>
{c.AddDefaultPolicy(policy =>{policy.AllowAnyOrigin()//允许所有来源的访问.AllowAnyHeader()//允许所有类型的请求头.AllowAnyMethod();//允许所有类型的请求});
});

启动跨越,在run之前

app.UseCors();
app.UseHttpsRedirection();

四、资源链接

vue.config.js文件

'use strict'
const path = require('path')
const defaultSettings = require('./src/settings.js')function resolve(dir) {return path.join(__dirname, dir)
}const name = defaultSettings.title || 'vue Admin Template' // page title// If your port is set to 80,
// use administrator privileges to execute the command line.
// For example, Mac: sudo npm run
// You can change the port by the following methods:
// port = 9528 npm run dev OR npm run dev --port = 9528
const port = process.env.port || process.env.npm_config_port || 9528 // dev port// All configuration item explanations can be find in https://cli.vuejs.org/config/
module.exports = {/*** You will need to set publicPath if you plan to deploy your site under a sub path,* for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,* then publicPath should be set to "/bar/".* In most cases please use '/' !!!* Detail: https://cli.vuejs.org/config/#publicpath*/publicPath: '/',outputDir: 'dist',assetsDir: 'static',lintOnSave: process.env.NODE_ENV === 'development',productionSourceMap: false,devServer: {port: port,open: true,overlay: {warnings: false,errors: true},proxy:{'/api': { // api表示拦截以/api开头的请求路径target: 'http://localhost:5296/api', //跨域的域名changeOrigin:true,//是否开启跨域pathRewrite:{ '^/api':'' // 重写请求,把/api变为空字符}}}},configureWebpack: {// provide the app's title in webpack's name field, so that// it can be accessed in index.html to inject the correct title.name: name,resolve: {alias: {'@': resolve('src')}}},chainWebpack(config) {// it can improve the speed of the first screen, it is recommended to turn on preloadconfig.plugin('preload').tap(() => [{rel: 'preload',// to ignore runtime.js// https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],include: 'initial'}])// when there are many pages, it will cause too many meaningless requestsconfig.plugins.delete('prefetch')// set svg-sprite-loaderconfig.module.rule('svg').exclude.add(resolve('src/icons')).end()config.module.rule('icons').test(/\.svg$/).include.add(resolve('src/icons')).end().use('svg-sprite-loader').loader('svg-sprite-loader').options({symbolId: 'icon-[name]'}).end()// set preserveWhitespaceconfig.module.rule('vue').use('vue-loader').loader('vue-loader').tap(options => {options.compilerOptions.preserveWhitespace = truereturn options}).end()config.when(process.env.NODE_ENV !== 'development',config => {config.plugin('ScriptExtHtmlWebpackPlugin').after('html').use('script-ext-html-webpack-plugin', [{// `runtime` must same as runtimeChunk name. default is `runtime`inline: /runtime\..*\.js$/}]).end()config.optimization.splitChunks({chunks: 'all',cacheGroups: {libs: {name: 'chunk-libs',test: /[\\/]node_modules[\\/]/,priority: 10,chunks: 'initial' // only package third parties that are initially dependent},elementUI: {name: 'chunk-elementUI', // split elementUI into a single packagepriority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or apptest: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm},commons: {name: 'chunk-commons',test: resolve('src/components'), // can customize your rulesminChunks: 3, //  minimum common numberpriority: 5,reuseExistingChunk: true}}})// https:// webpack.js.org/configuration/optimization/#optimizationruntimechunkconfig.optimization.runtimeChunk('single')})}
}

Program.cs文件

using System.Configuration;
using WebApplication5;var builder = WebApplication.CreateBuilder(args);// Add services to the container.//配置跨域
builder.Services.AddCors(c =>
{c.AddDefaultPolicy(policy =>{policy.AllowAnyOrigin()//允许所有来源的访问.AllowAnyHeader()//允许所有类型的请求头.AllowAnyMethod();//允许所有类型的请求});
});builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();var app = builder.Build();app.UseCors();
app.UseHttpsRedirection();if (app.Environment.IsDevelopment())
{app.UseSwagger();app.UseSwaggerUI();
}app.UseHttpsRedirection();app.UseAuthorization();app.MapControllers();app.Run();
http://www.yayakq.cn/news/101586/

相关文章:

  • 如何做企业网站方法wordpress加载中
  • 浙江建设厅网站官网微信公众平台小程序登录
  • 江西专业的网站建设公司seo代码优化步骤
  • 做网站最下面写什么软件wordpress文章只显示摘要
  • 石家庄网站建设排名常州市网站建设设计
  • 永嘉县住房建设局网站大连网站建设工作室
  • 免费自助建站系统大丰网站建设找哪家好
  • wordpress网站加载效果搜索引擎优化作业
  • 网站设计风格有哪几种深圳企业企业网站建设
  • ps设计师网站wordpress修改数据库链接信息
  • 杨凌企业网站建设wordpress momo
  • 1.1做网站的目的搜索引擎营销的成功案例
  • 超云建站销售平台排行榜前十名
  • 广播电台网站建设方案做平面的公司网站
  • 设计网站公司的账务处理做网站一定要虚拟主机吗
  • 锦州网站制作公司西安seo服务公司
  • 网站空间域名注册瑞安 网站建设培训
  • 黄冈建设局网站湖南产品网络营销推荐咨询
  • 模版网站可以做seo吗深圳市响应式网站建设
  • 天津网站的建设苏州企业建设网站
  • 中国营销传播网手机版入口江西省seo
  • 做的网站必须备案网站打开慢的解决方法
  • 中小企业建设网站应注意wordpress优雅的暂停
  • 大唐网站设计软件开发公司在哪里
  • 河北省城乡建设培训网官方网站wordpress相册设置
  • 双阳区住房和城乡建设局网站定制app网站
  • 做静态页面的网站上海百度优化
  • 盐城网站优化公司想做电商网站运营要怎么做
  • 有哪些平面设计网站枣庄市住房和建设局网站
  • 酒店网站建设流程今标 网站建设