axios

How to test axios with config option

喜夏-厌秋 提交于 2020-12-13 03:30:40
问题 I'm trying to test the below axios request written for both put/post as a config option: export function saveCourse(course){ const config = { method: course.id ? 'PUT' : 'POST',// POST for create, PUT to update when id already exists. url: baseUrl + (course.id || ''), headers: { "content-type": "application/json" }, data: course } return axios(config) .then((res) => { if(res.status === 201 || res.status === 200) return res.data; if(res.status === 400){ const error = res.text(); throw new

跨域 webpack + vue-cil 中 proxyTable 处理跨域

*爱你&永不变心* 提交于 2020-12-12 15:00:19
博客地址: https://ainyi.com/27 跨域 了解同源政策:所谓"同源"指的是"三个相同"。 协议相同 域名相同 端口相同 解决跨域 jsonp 缺点:只能get请求 ,需要修改B网站的代码 cors 这个方案缺点 是 ie6 7 兼容不好(倒是不见得要兼容)。需要B网站在响应中加头 postMessage 缺点也是 ie6 7 兼容不好(倒是不见得要兼容)。需要修改B网站的代码 iframe window.name 传值得方式很巧妙,兼容性也很好。但是也是需要你能修改B网站代码 服务端主动请求B网站,兼容性好而且你客户端的代码还是原来的ajax,缺点是感觉不好。(服务器端是不存在跨域安全限制的) 类似5 用nginx把B网站的数据url反向代理。 node, express 解决跨域 加上请求头: 1 app.all('*', (req, res, next)=> { 2 res.header("Access-Control-Allow-Origin", "*" ); 3 res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With" ); 4 res.header("Access-Control

使用proxyTable解决vue里的跨域问题

前提是你 提交于 2020-12-12 13:55:02
由于没有跨域的接口,所以,用8080端口请求8081端口,来模拟跨域。跨域会出现下面报错。 1.找到config文件夹下index.js,在proxyTable对象里复制以下代码: proxyTable: { '/apis' : { // 测试环境 target: 'http://localhost:8081', // 接口域名 changeOrigin: true , // 是否跨域 pathRewrite: { '^/apis': '' // 需要rewrite重写的, } } },  注意:【更改完这个配置文件后,需要重启项目】 2.使用fetch,vue-resource或axios请求接口 fetch请求: // 用 /apis代替http://localhost:8082 fetch("/apis").then(res=> { console.log(res); }) axios请求: this .$axios.get("/apis").then(res=> { console.log(res); }) vue-resource请求: this .$http.get("/apis").then(res=> { console.log(res); }); 这样请求,就不会跨域了: 来源: oschina 链接: https://my.oschina.net/u

2018 vue前端面试题

独自空忆成欢 提交于 2020-12-12 13:52:56
1、active-class是哪个组件的属性?嵌套路由怎么定义? 答:vue-router模块的router-link组件。 2、怎么定义vue-router的动态路由?怎么获取传过来的动态参数? 答:在router目录下的index.js文件中,对path属性加上/:id。 使用router对象的params.id 3、vue-router有哪几种导航钩子? 答:三种,一种是全局导航钩子:router.beforeEach(to,from,next),作用:跳转前进行判断拦截。第二种:组件内的钩子;第三种:单独路由独享组件 4、scss是什么?安装使用的步骤是?有哪几大特性? 答:预处理css,把css当前函数编写,定义变量,嵌套。 先装css-loader、node-loader、sass-loader等加载器模块,在webpack-base.config.js配置文件中加多一个拓展:extenstion,再加多一个模块:module里面test、loader 4.1、scss是什么?在vue.cli中的安装使用步骤是?有哪几大特性? 答:css的预编译。 使用步骤: 第一步:用npm 下三个loader(sass-loader、css-loader、node-sass) 第二步:在build目录找到webpack.base.config.js

Axios is not sending cookies

点点圈 提交于 2020-12-12 13:29:14
问题 I have two apps, the server-side app which is written in Laravel and the client-side app, written in VueJS. The vue app consumes the api provided by the laravel app. The auth flow: The user attempts to log in, the server sends two tokens to the client, a) access_token and b) refresh_token upon successful login. The server also sends the refresh token in the form of an httpOnly cookie to the client so that when the access token is expired, it can be refreshed using the refresh token from the

Axios is not sending cookies

爷,独闯天下 提交于 2020-12-12 13:28:03
问题 I have two apps, the server-side app which is written in Laravel and the client-side app, written in VueJS. The vue app consumes the api provided by the laravel app. The auth flow: The user attempts to log in, the server sends two tokens to the client, a) access_token and b) refresh_token upon successful login. The server also sends the refresh token in the form of an httpOnly cookie to the client so that when the access token is expired, it can be refreshed using the refresh token from the

React - Axios call make too many requests

旧街凉风 提交于 2020-12-12 05:09:30
问题 Im learning React & Redux by making a game project. I want to fetch data (attributes) by API, but it cause too many requests. Guess it can be realted to placing axios call directly in functional react component, but i have no idea how to fix it. function Attributes({ attributes, dispatch }) { axios.get(`/api/heroes/1/get-attributes`).then(res => { dispatch(AttribAction.set(objectToArray(res.data))); }); return ( <div className="content"> {attributes.map((attrib, index) => ( <div key={index}

前端学习(2708):重读vue电商网站28之通过axios请求拦截器添加 token

梦想与她 提交于 2020-12-11 12:49:28
通过axios请求拦截器添加 token,保证拥有获取数据的权限。 原因是,后台那边除开登录的 api ,其它都需要进行授权 。 因此,我们可以利用 axios 中 interceptors 属性,其中有一个成员 request ,此时我们可以通过 use 函数为请求拦截器挂载一个回调函数,只要向服务器端发送了一个 axios 请求,会优先调用 use 函数。 首先,在 main.js 添加如下代码: 此时,打印 config ,查看结果如下,发现我们 headers 字段并没有一些授权字段。 此时,我们添加如下一行代码,通过 token 来进行授权。 此时,在 Network 就能查看到有一个 Authorization 字段了,但这里是为 null ,因为我们进行的是登录请求,在登录期间,服务器是不会颁发令牌( token )。如果登录之后,调用其它 api 接口的话,就会颁发相应的 token 令牌。 来源: oschina 链接: https://my.oschina.net/u/4389791/blog/4791920

Spring Boot + Vue 前后端分离,两种文件上传方式总结!

回眸只為那壹抹淺笑 提交于 2020-12-11 12:24:16
松哥原创的 Spring Boot 视频教程已经杀青,感兴趣的小伙伴戳这里--> 松哥要升级 SpringBoot 视频了,看看新增了哪些内容! 在Vue.js 中,如果网络请求使用 axios ,并且使用了 ElementUI 库,那么一般来说,文件上传有两种不同的实现方案: 通过 Ajax 实现文件上传 通过 ElementUI 里边的 Upload 组件实现文件上传 两种方案,各有优缺点,我们分别来看。 准备工作 首先我们需要一点点准备工作,就是在后端提供一个文件上传接口,这是一个普通的 Spring Boot 项目,如下: SimpleDateFormat sdf = new SimpleDateFormat( "/yyyy/MM/dd/" ); @PostMapping ( "/import" ) public RespBean importData (MultipartFile file, HttpServletRequest req) throws IOException { String format = sdf.format( new Date()); String realPath = req.getServletContext().getRealPath( "/upload" ) + format; File folder = new File

Vue3 系统入门与项目实战完整无密

人走茶凉 提交于 2020-12-08 19:58:16
下载: Vue3 系统入门与项目实战完整无密 谁说为0基础准备的课,就一定浅薄?本课程带你轻松入门、深度掌握 Vue3,夯实前端硬技能。课程从 Vue3 基础语法,到组件原理,动画,代码设计,再到新语法扩展,由浅入深,全面、系统地梳理 Vue 知识点。在学习过程中,还有老师多年的“避坑经验”倾囊相授 ,并在最后带你按照企业级别代码质量和工程开发流程完成“京东到家”应用,实现对框架的彻底掌握。 适合人群 想要从零开始彻底入门 Vue 的同学; 想要了解清楚 Vue3 原理和新语法的同学; 希望扩展前端知识面,寻求升职加薪机会的同学 技术储备要求 熟悉JS基础语法; 了解Npm开发环境; 了解Webpack基本操作 第1章 Vue 语法初探 试看 本章中,将会通过编写实际例子,带你对Vue的语法有个粗浅的认知,让大家结合例子,有一些自己的疑问,从而带着问题继续学习,以便于更好的理解和掌握后面的知识点。 共 5 节 (57分钟) 收起列表 1-1 课前须知,这里有你需要了解的一切 (04:34) 试看 1-2 初学编写 HelloWorld 和 Counter (14:41) 1-3 编写字符串反转和内容隐藏小功能 (09:32) 1-4 编写TodoList 小功能,了解循环和双向绑定 (11:18) 试看 1-5 组件概念初探,对 TodoList 进行组件代码拆分 (16:47)