axios

Nuxt How to set baseURL in dev or production

别等时光非礼了梦想. 提交于 2019-12-08 04:05:36
问题 This seems like a simple Nuxt question, but I just can't figure it out. When running "NPM run dev" I want to set the Axios baseURL to "localhost/api" and when running from the dist folder after "NPM run generate" I want the baseURL to be "/api". Is there a simple solution? 回答1: This is the way to do it: let development = process.env.NODE_ENV !== 'production' module.exports = { axios: { baseURL: development ? 'http://localhost:3001/api' : 'https://domain/api' }, modules: [ '@nuxtjs/axios' ], }

npm i and npm update breaking gulp, browserify builds

老子叫甜甜 提交于 2019-12-08 03:58:09
问题 What were you expecting to happen? Gulp to transpile vue.js components into usable and functional JS. What actually happened? When I run gulp contacts (shown under the Code and Configuration section below), the transpiling runs fine. No errors are outputted in the terminal, and everything appears to complete successfully. The problem is, when the page is reloaded I have an error in the console stating Uncaught SyntaxError: Unexpected end of input . When looking at the source, devtools shows

Lumen API CORS Ajax 405 Method Not Allowed

痴心易碎 提交于 2019-12-08 03:20:22
问题 I have an api on Laravel Lumen, we test via Postman and Ruby Rest Client and all go very well, but we create a simple Auth Login that response a web token, all works fine but on our React App actually we have this "405 405 Method Not Allowed". We create a class with the next code: <?php namespace palanik\lumen\Middleware; use Closure; use Illuminate\Http\Response; class LumenCors { protected $settings = array( 'origin' => '*', // Wide Open! 'allowMethods' => 'GET,HEAD,PUT,POST,DELETE,PATCH

Rendering json data with axios

大憨熊 提交于 2019-12-08 02:58:00
问题 I'm trying to get data from .json file. Nothing appears on the page. Maybe somebody have an idea why? Thanks! This is link on the file https://s3-us-west-2.amazonaws.com/digicode-interview/Q1.json import React from 'react'; import createReactClass from 'create-react-class'; import ReactDOM from 'react-dom'; import axios from 'axios'; class Data extends React.Component { constructor(props) { super(props); this.state = { array: [] }; } componentDidMount(){ axios .get('https://crossorigin.me

Socket hang up when using axios.get, but not when using https.get

爱⌒轻易说出口 提交于 2019-12-08 02:47:55
问题 To the best of my knowledge, I am doing the same thing using 2 different approaches: const https = require("https"); const axios = require("axios"); let httpsAgent = new https.Agent({rejectUnauthorized: false}); axios.get(`https://${hostname}:${port}${path}`, {httpsAgent}) .then((data) => { console.log("axios success: " + data.substr(0, 100)); }) .catch((error) => { console.log("axios error: " + error); }); let data = ""; https.get({ hostname, path, port, agent: httpsAgent }, (response) => {

Axios Get request data comes back with “data: ↵ ↵ ↵ ↵”

ぐ巨炮叔叔 提交于 2019-12-08 00:35:06
问题 I am using Axios to make a get request to a Jobs API site. Whenever I console.log the response, I can't seem to use it. The object that comes back is {data: "↵ ↵ ↵ ↵"}, but it looks like JSON. const url = //api string content axios.get(url) .then(function(res){ console.log(res); }) .catch(function(){ console.log("err"); }) If I console.log(res.data), then it doesn't come back parsed in JSON. It looks like it's returning a function with all the data. It looks like displayJobs({"keys": "values"

Vuejs2.0学习笔记之axios&vue-resource

旧城冷巷雨未停 提交于 2019-12-07 21:34:16
在Vue中发送AJAX请求:Vue本身并不支持发送ajax请求,需要使用第三方插件vue-resources(1.0, 但是2.0中不建议使用)、官方推荐使用axis(2.0);但是也可以用jQuery; 什么是axios?axios是一个基于promise的http请求客户端,用来发送请求,也是vue2.0官方推荐使用的;在vue2.0官方推荐的,同时不再对vue-resource进行更新和维护。 axios的github地址和使用方式: https://github.com/axios/axios 使用axios说明: axios([options]) axios.get(url[,options]); 传参方式: 1.通过url传参 2.通过params选项传参 axios.post(url,data,[options]); axios默认发送数据时,数据格式是Request Payload,并非我们常用的Form Data格式, 所以参数必须要以键值对形式传递,不能以json形式传参 传参方式: 1.自己拼接为键值对 2.使用transformRequest,在请求发送前将请求数据进行转换 3.如果使用模块化开发,可以使用qs模块进行转换 axios本身并不支持发送跨域的请求,没有提供相应的API,作者也暂没计划在axios添加支持发送跨域请求,所以只能使用第三方库

How to access objects in google cloud storage?

柔情痞子 提交于 2019-12-07 17:24:52
问题 I am trying to build an application that will access files in my google cloud storage while the bucket is private. The docs arent clear on what to do to enable access of the bucket from a server. I have the json file which they provide. I plan on using to expose the files on the bucket using nodejs but I'm not sure how to authorize requests to the bucket. I am using axios by the way. Do i create an API key or use a key as a query string? Some help would be appreciated! 回答1: You want Google

How to display data from api in react component

这一生的挚爱 提交于 2019-12-07 15:21:43
I am using axios to get data from an API and the retrieved data was successfully dispatched to the store, I currently have some problems in displaying the data in my React component. I was able to console.log the data successfully but it turns out my component renders before the data was fully retrieved from the API. Below is the component to display the data: import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import { bindActionCreators } from 'redux'; import HeaderSidebar from './includes

AXIOS: how to run http requests concurrently and get the result of all requests event if a request fails

六眼飞鱼酱① 提交于 2019-12-07 14:33:52
问题 I am trying to make server get requests concurrently, in order to do that I have written the following function. Problem If a single call is failing then I am not able to get the response of rest of the requests. export const getAll = async (collection) => { return new Promise((resolve, reject) => { const requests = collection.map(req => { const config = { headers: req.headers, params: req.params } return axios.get(req.url, config); }) axios.all(requests) .then(axios.spread((...args) => { //