axios

How to access json file in src folder created using create react app

岁酱吖の 提交于 2019-12-12 01:15:09
问题 I'm a newbie to react. I have created react application using npx create-react-app. In actions,axios.get is throwing localhost:3000 file not found error. Below is the code which is in src/actions/index.js export function lang(language) { let url = "./../resources/strings/strings_" + language + ".json"; return dispatch => { axios.get(url).then(response => { console.log(response.data) }).catch(response => { console.log(response); }); } } This is the project structure [1]: https://i.stack.imgur

Vue File Upload with Parameters

时光总嘲笑我的痴心妄想 提交于 2019-12-11 23:18:23
问题 Hi Guys i create a component to upload files and its working so far, but along with the data I'll like to pass some parameters too, for example HTML <div class="col-md-4"> <div class="container"> <div class="large-12 medium-12 small-12 cell"> <label> Files <input type="file" name="file" ref="files" multiple v-on:change="fileChange($event.target.files)" /> </label> <v-btn outline color="primary" dark v-on:click="upload()">Submit</v-btn> </div> </div> </div> Script import api from '../store/api

Setting baseUrl for Axios in Vue js sends out request

ε祈祈猫儿з 提交于 2019-12-11 21:53:22
问题 In my app I use Axios to handle my API-requests. In main.js I have set the baseUrl. Without me making a request it makes a request on its own just by setting the baseUrl, so always when the app is loaded in the browser. In my main.js axios.defaults.baseURL = 'https://domain.nl/path/to/my/api All works fine but a request to the baseUrl gives back a 500 for not requesting data. The implementation in main.js: import axios from 'axios' import VueAxios from 'vue-axios' config: axios.defaults

Failed call to Deezer API with React and axios

不想你离开。 提交于 2019-12-11 19:46:24
问题 I want to connect to Deezer API and read data, the API is available here, if you take first links they have there and open in a new tab you will see the data in json, however Axios can't return it import React from "react"; import ReactDOM from "react-dom"; import axios from "axios"; import "./styles.css"; class App extends React.Component { componentDidMount() { axios.get("https://api.deezer.com/album/302127") .then(response => { console.log(response); }) .catch(err => { console.log(err); })

Sailsjs + vuejs + axios + CSRF tokens

半城伤御伤魂 提交于 2019-12-11 19:31:30
问题 i some thing not understand. Always get an error 403. I have a code in frontend(vue.js), here I get a token _csrf from Sails.js, its ok. axios.get('http://localhost:1337/csrfToken') .then(response => { this.$store.commit('csrf_update', response.data._csrf); console.log("_csrf===",response.data._csrf); axios.defaults.headers.post['X-CSRF-Token'] = response.data._csrf; }) And i have a backend sails.js, settings in security.js cors: { allRoutes: true, allowOrigins: 'http://localhost:8080',

How to use axios response data in data function - vue

只谈情不闲聊 提交于 2019-12-11 18:32:29
问题 Using axios to fetch api data: fetchData () { axios.get(globalConfig.OFFERS_URL) .then((resp) => { this.offersData = resp.data console.log(resp) }) .catch((err) => { console.log(err) }) } Data function: data () { return { offersData: {} } } Now i can use fetched data in my template, like so: {{ offersData.item[0].id }} But can i set the fetched data in a data function: data () { return { offersData: {}, id: this.offersData.item[0].id } } It's not working for me, is that even possible to store

axios.post automatically splice url with my params

六月ゝ 毕业季﹏ 提交于 2019-12-11 18:26:20
问题 I want to implement an api with vue and axios in my front-end: methods:{ startSpider:function(event){ alert("spider is ready to run!"); let data = {'searchKey':this.searchKey, 'category':this.category, 'num':this.num}; axios.post("{% url 'main:getCommodityInfo'%}", data, {headers:{'X-CSRFToken': this.getCookie('csrftoken')}}) .then(response=>{ console.log(response.data) }) .catch(error=>{ console.log(error); alert("connection has error") }) }, When I call this function, I expect to get data

React Router + Axios interceptors. How to Do a redirect?

∥☆過路亽.° 提交于 2019-12-11 17:47:47
问题 I have an axios interceptors and when a user gets forced logged out(because of expired token) I want to go back to my home page. I am not sure how to pass react router to it though. I am using mobx but not sure if that will help me with this problem. export const axiosInstance = axios.create({ baseURL: 'https://localhost:44391/api', timeout: 5000, contentType: "application/json", Authorization: getAuthToken() }) axiosInstance.interceptors.response.use(function (response) { return response; },

React Native android app throws Network Error when upload on App store

别说谁变了你拦得住时间么 提交于 2019-12-11 17:23:38
问题 I am working on an app which is used to get Tenders data across the country. I am using axio to post and get data and everything works fine. I have generated Apk and tested it on simulators and Bluestaks but when I published the app yesterday then app started to throw the network error on login page. This is the first time I am getting the error and I am badly stuck now. please somebody help me My package.json file is dependencies are "dependencies": { "axios": "^0.19.0", "firebase": "^5.11.1

Execute many promises sequentially (Concept)

心不动则不痛 提交于 2019-12-11 17:08:55
问题 (My target is clarify my concept about the problem, not code) I want execute a array of promises sequentially, but nodeJS throw a strange error about many promises executed in parallel.(Because i limited that array to 20 promises and works, 50 promises and works, but 9000 promises and explode..) I know that we have some solutions like, array.reduce(), loops, etc I know about the promises states (my array have pending promises initially) My question: I can execute 20 promises, then another 20