axios

Axios Api calls in Heroku

笑着哭i 提交于 2021-02-04 21:44:00
问题 I've deployed my app to heroku and I have it connected to mongoLab. My problem is my API calls using axios wont't work with Heroku because they are still set up locally. Is there a dynamic env variable I have to replace baseURL with for it to work? I tried researching this with no luck. See Code below export default { saveClient: function(clientData) { return axios({ method:"post", url:"/api/saveClient", baseURL:"http://localhost:3001", data:clientData }) } ---------------------- server.js is

ReactJS browser app cannot see things in the Docker Compose network

…衆ロ難τιáo~ 提交于 2021-02-04 19:47:26
问题 I have a ReactJS project with its own Dockerfile, exposing port 3000:3000. I also have a PHP project with its own Dockerfile, exposing port 80:80. The PHP app also has containers for MySQL, Redis and Nginx For the PHP app, I have a docker-compose file that creates a network ( my-net ) for PHP, Nginx, MySQL and Redis to communicate on. However, I now want the ReactJS (which is in a separate project) to be able to communicate with the PHP app. I added a docker-compose file to the React project,

Using Environment Variables in nuxt.config.js

不打扰是莪最后的温柔 提交于 2021-02-04 18:16:05
问题 I'm using Nuxt & Axios but having trouble using environment variables when building the application from my local machine . I have installed the @nuxtjs/dotenv module in an attempt to fix this issue but still having problems. Note: The environment variables work fine when building the app within my hosting providers environment. It is only building from my local machine that gives me trouble. My IDE is VS Code. Here is my axios setup inside nuxt.config.js: module.exports = { ... buildModules:

VueJS - Unable to catch the axios error in Vue/CLI project

落花浮王杯 提交于 2021-02-04 08:28:52
问题 Hello i am trying to display a message whenever the API has any error, here $http is axios The code is given Below: Case 1 ... <span class="badge" id="disconnected" v-if="noerror" >{{noerror.name}}</span> <span class="badge" id="disconnected" v-if="error" >{{error}}</span> ... isData: false, error: null, noerror: null, ... status(id) { this.$http.get(`/status_init/${id}`) .then(response => { this.noerror = response.data this.isData = true }) .catch ((e) => {this.error = 'No data'}) } Case 2 .

vue --- axios发post请求后台接收不到参数的三种解决方案

放肆的年华 提交于 2021-02-03 01:58:34
最近用vue 做项目使用axios 发送post 请求时遇到了前端传数据后端接收不到的情况: 后来仔细对比发现axios传值是这样的: 而 ajax 传值是这样的: 一个 Request Payload , 一个Form data. 将Request payload 转为 from data 格式就可以了。有四种方式: 一:使用qs(推荐) 首先在你的项目里安装qs 模块。 npm install qs --save-dev 然后在需要使用的页面引入一下: import qs from ' qs ' 引入好了之后,把上面的postData用qs转一下再发送给后台就可以了: let postData = qs.stringify({ certificationAccount: that.certificationAccount, balance: that.balance }) 这样发送给后台时就是Format Data格式了。 二:使用URLSearchParams ; let postData= new URLSearchParams() postData.append('certificationAccount', that.certificationAccount) postData.append('balance', that.balance) 这样也可以

vue --- axios发post请求后台接收不到参数的三种解决方案

自作多情 提交于 2021-02-03 00:09:34
vue --- axios发post请求后台接收不到参数的三种解决方案 参考文章: (1)vue --- axios发post请求后台接收不到参数的三种解决方案 (2)https://www.cnblogs.com/yuerdong/p/10277177.html 备忘一下。 来源: oschina 链接: https://my.oschina.net/u/4277087/blog/4906903

.net core3.1 webapi + vue.js + axios实现跨域

元气小坏坏 提交于 2021-01-30 08:52:30
我所要讲述的是,基于.net core3.1环境下的webapi项目,如何去使用axios对接前端的vue项目 既然谈到axios,这里贴出axios的官方文档地址: http://www.axios-js.com/zh-cn/docs/ 首先是前端部分进行设置 第一步,在vue项目中安装axios 在vs code的终端中输入命令 npm install axios 稍等片刻,即可完成安装 第二步,构建axios的测试api 首先需要在main.js中,引入前面安装的axios 然后在某个组件的钩子函数里,写入以下代码 在组件被创建的时候,向后台发送get请求,获取数据。如果对axios的api不太熟悉的话,可以转到 axios的官方文档 当然我也为新手提前准备好了截图,供查阅 上面这张图片来自于axios的官方文档 前端部分就此完成 接下来是配置.net core webapi项目 其实后端的配置极其简单,只需启用cors,然后做一些服务注入和中间件的添加即可 在微软的文档中也有对这部分给出了相关的注解,这里可以选择查阅 微软的官方文档 第一步,服务注入 在startup.cs中加入以下代码 readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins"; #region cors services

基于 Laravel + Vue 构建一个类似 Twitter 的 Web 应用

时光毁灭记忆、已成空白 提交于 2021-01-30 05:48:22
在这一篇示例教程中,我们将会构建一个类似 Twitter 的 Web 应用。我们将使用到 Laravel 和 Vue.js,并且在 Vue.js 中定义一些组件,此外,还会使用 Axios 来发送网络请求。当然,篇幅有限,我们不可能开发一个完整的 Twitter 应用,而是实现一个简化版:用户可以发送 Tweet 并在自己的时间线中看到,可以关注或取消关注其他用户,如果关注了其他用户,那么也可以看到关注用户发布的 Tweet。麻雀虽小,五脏俱全,希望大家可以通过这个简单的应用学会 Laravel 和 Vue.js 的基础用法。 安装配置 Laravel 首先,我们需要安装一个新的 Laravel 应用(也可以通过 Composer 安装,看个人喜好): laravel new laratwitter 进入该项目根目录,安装前端依赖: npm install 接下来,修改 .env 中数据库相关配置符合本地环境,然后通过如下命令生成用户认证脚手架代码: php artisan make :auth 运行如下命令生成相关数据表: php artisan migrate 接下来配置下 Web 服务器(使用 Valet 的话略过),我这里配置的域名是 laratwitter.test ,配置完成后重启下 Web 服务器,然后通过 http://laratwitter.test

Fetch post request works but axios post does not?

谁都会走 提交于 2021-01-29 20:39:57
问题 Currently trying to convert a working fetch POST request into an Axios POST request, however, I keep getting the error "Error: Request failed with status code 400". The function is a post request to the Spotify API to obtain an authentication token. Would greatly appreciate any help :) This is the current Fetch POST request that works : const result = await fetch('https://accounts.spotify.com/api/token', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded',

Node.js - csurf invalid csrf token

冷暖自知 提交于 2021-01-29 18:57:47
问题 I'm using the npm module csurf for generating a token. First I get the token from the server, which I then use for the /register request. When I'm reproducing the same steps with postman, it seems to work, but unfortunately not in the application. There it always throws the error message that the token is invalid --- Server side --- csrfProtection.js import csrf from 'csurf'; export default csrf({ cookie: true }); router.js import csrfProtection from './../../config/csrfProtection' router.get