axios

how to re-render after getting axios response in jest test

感情迁移 提交于 2020-01-13 06:30:48
问题 My component: componentDidMount() { // Make HTTP reques with Axios axios.get(APIConfig.api_profile()).then((res) => { // Set state with result this.setState(res.data); console.log('I was triggered during componentDidMount') console.log(res) }); } And my test: //@see https://github.com/ctimmerm/axios-mock-adapter mock.onGet(APIConfig.api_profile()).reply(200, { "id_user": "1", "id_person": "1", "imageUrl": "", "email": "xyz@zyz.com", "name": "xyz xyz" }); test('xyz', async() => { var

Load data before createStore

↘锁芯ラ 提交于 2020-01-11 12:08:30
问题 I’ve created some React files where one initializes a Redux store. However, I really need to load some data from a json file before store is initialized. I’ve tried to import a script loading the json structure then assigning it to the createStore initialState value. But createStore runs before the data is loaded and assigned. Is there any simple way to say “dont do anything before my axios call is done”??? 回答1: Action types actiontypes.js export const LOAD_DATA_REQUEST='LOAD_DATA_REQUEST';

[开源] SEPP——研发协作一站式管理平台

陌路散爱 提交于 2020-01-08 17:44:27
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 演示地址 http://www.seqcer.com/ 仅对chrome浏览器做了完全适配,其他chromium核心浏览器或者firefox、safari也能使用,但是不推荐 仓库地址: 前端: https://github.com/purang-fintech/seppf.git 后端: https://github.com/purang-fintech/seppb.git 监控中心服务: https://github.com/fudax/octopus 本地化部署问题解决步骤: 先赏个STAR 再加QQ群:362260709 再问问题,当然,建议提问之前仔细看完下面的说明 技术栈 前端:vue2、axios、element等等等等 后端:springboot、guava、lombok等等等等 基础组件:mariadb(10.3)、nginx(1.15.3)、nodejs(8.12.0)、fastdfs、npm(6.7.0)、webpack4等等 插件:swagger2、quartz、aviator、h2等等 后端readme 启动方式: Main Class:com.pr.sepp.SeppApplication(线上可注释掉@EnableSwagger2) 本地VM options:-Denv=local

vue-cli-element-ui-scss-axios

人走茶凉 提交于 2020-01-08 15:24:37
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 初始化 cnpm i vue-cli -g vue init webpack html cd html cnpm i node-sass sass-loader less less-loader -D cnpm i element-ui -S cnpm i axios qs js-cookie -S npm run dev src/assets/scss/element-variables.scss $--color-primary: #315ca1 !default; $--font-path: '../../../node_modules/element-ui/lib/theme-chalk/fonts'; @import "../../../node_modules/element-ui/packages/theme-chalk/src/index"; src/config.js export default { title: '云管理系统', baseUrl: 'http://localhost:13000/api/msweb', } src/http.js import axios from 'axios' import qs from 'qs' import cache from './cache'

Axios wait on endpoint promise before returning data

末鹿安然 提交于 2020-01-07 05:07:26
问题 I have an express endpoint that I call that has a function with a promise inside: Express Server: // endpoint app.get('/test', function (req, res) { res.setHeader('Content-Type', 'application/json') let y = 1 let x = 1 let bar = foo(x, y) res.json({a: bar}) } const foo = (x, y) => { // The promise sue.young(y, function(error, output) { // do stuff with x and output // console.log(output.result) // expected data in console // I need to return "output.result" }) } View: let axiosClient = axios

[技术翻译]使用Nuxt生成静态网站

倾然丶 夕夏残阳落幕 提交于 2020-01-07 00:14:18
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 本周再来翻译一些技术文章,本次预计翻译三篇文章如下: 04.[译]使用Nuxt生成静态网站 ( Generate Static Websites with Nuxt ) 05.[译]Web网页内容是如何影响电池功耗的 ( How Web Content Can Affect Power Usage ) 06.[译]在现代JavaScript中编写异步任务 ( https://web.dev/off-main-thread/ ) 我翻译的技术文章都放在一个github仓库中,如果觉得有用请点击star收藏。我为什么要创建这个git仓库?目的是通过翻译国外的web相关的技术文章来学习和跟进web发展的新思想和新技术。git仓库地址: https://github.com/yzsunlei/javascript-article-translate 静态网站如今再次流行起来了。信息站和品牌宣传站不再需要使用WordPress之类的内容管理系统来动态更新。 使用静态网站生成器,您可以从无源CMS,API等动态源以及Markdown文件等文件中获取内容。 Nuxt是基于Vue.js的出色的静态网站生成器,可轻松用于构建静态网站。使用Nuxt,从动态内容构建静态网站所需要做的就是创建模板

Nuxt.js学习(八) --- 异步数据

孤街醉人 提交于 2020-01-06 20:53:22
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> [TOC] 1、异步数据 1.1、官方文档: Nuxt.js 扩展了 Vue.js,增加了一个叫 asyncData 的方法,使得我们可以在设置组件的数据之前能异步获取或处理数据。 asyncData 方法 asyncData 方法会在组件( 限于页面组件 )每次加载之前被调用。它可以在服务端或路由更新之前被调用。 在这个方法被调用的时候,第一个参数被设定为当前页面的 上下文对象 ,你可以利用 asyncData 方法来获取数据,Nuxt.js 会将 asyncData 返回的数据融合组件 data 方法返回的数据一并返回给当前组件。 注意:由于asyncData方法是在组件初始化前被调用的,所以在方法内是没有办法通过 this 来引用组件的实例对象。 Nuxt.js 提供了几种不同的方法来使用 asyncData 方法,你可以选择自己熟悉的一种来用: 返回一个 Promise , nuxt.js会等待该 Promise 被解析之后才会设置组件的数据,从而渲染组件. 使用 async 或 await ( 了解更多 ) 我们使用[axios]重构HTTP请求,我们强烈建议您使用[axios模块]用于您的Nuxt项目中。 如果您的项目中直接使用了 node_modules 中的 axios ,并且使用 axios

repetedly call a axios.get to display data from endpoint

倾然丶 夕夏残阳落幕 提交于 2020-01-06 13:58:16
问题 I working on backend written in flask that returns REST API for various task, one of which is to request deployment, Then log gets filled in the database. So I have created another REST API endpoint to return log message for the specific request id. Now what I want is to once the showStatus is true the log_url used by axios.get should be constantly hitting and retrieving data from the backend endpoint retrieving data after 30 seconds. and show it in the show below as statusMessage . <script>

Get a 401 error with POST and PUT Laravel passport/Vue/Axios

冷暖自知 提交于 2020-01-06 12:29:29
问题 I am working on a Vue application with a seperate Laravel back-end API. The back-end has Laravel passport that requires an access token when doing database calls. Normally everything goes right, I can get data back from the database but for some reason, 2 of my calls gets errors, the POST en PUT. I don't know why I get unauthenticated (401) from laravel passport back, while my get request is going well. Also, both POST and PUT are going fine in the postman application. The get request

Get a 401 error with POST and PUT Laravel passport/Vue/Axios

醉酒当歌 提交于 2020-01-06 12:27:28
问题 I am working on a Vue application with a seperate Laravel back-end API. The back-end has Laravel passport that requires an access token when doing database calls. Normally everything goes right, I can get data back from the database but for some reason, 2 of my calls gets errors, the POST en PUT. I don't know why I get unauthenticated (401) from laravel passport back, while my get request is going well. Also, both POST and PUT are going fine in the postman application. The get request