Axios send a POST request to submit form dataBy default, Axios serializes JavaScript objects into JSON. To send data in application/x-www-form-urlencoded format, you can use one of the following options.1. Browser. In the browser, you can use the Urlsearchparams API as follows:var params = new Urlsearchparams ();p arams.append (' param1 ', ' value1 ');p arams.append (' param2 ', ' value2 '); Axios.post ('/
Cross-domain requests are common problems with HTTP requests.The Vue framework recommends using the Axios plug-in Request data, if the background does not do cross-domain request processing, then the foreground can use the Axios plug-in combined with the QS plugin to achieve cross-domain requests.
Installing plugins
npm install --save axiosnpm install --save qs
Introducing Plugins
import
InstallationUsing NPM:$ NPM Install Axiosor use Bower:$ Bower Install AxiosOr use CDN directly:Main.js settings are as followsIntroduction of AxiosImport Axios from ' Axios 'The prototype attached to VueVue.prototype. $http = AxiosSet the agent in the Webpack.config.js (config->index.js) file to note that the new file will be modifiedDev: {env:require ('./dev.env '), Port:8080,//set the port number of the a
InstallationUsing NPM:$ NPM Install Axiosor use Bower:$ Bower Install AxiosOr use CDN directly:Main.js settings are as followsIntroduction of AxiosImport Axios from ' Axios 'The prototype attached to VueVue.prototype. $http = AxiosSet the agent in the Webpack.config.js (config->index.js) file to note that the new file will be modifiedDev: {env:require ('./dev.env '), Port:8080,//set the port number of the a
In some specific scenarios (for example 即时搜索 , 表格分页 ), Ajax requests are frequently initiated, and since Ajax is an asynchronous API, the returned timing is not guaranteed, and it is time to implement an AJAX queue that cancels processing the previous request when the same request is initiated.When used jquery.ajax , it is possible to interrupt processing of the Ajax return value in a more convenient abort way, but because axios it is dependent, it ca
This time to tell the project need to use the Vue.
When I first started framing, I used the vue-resource to see the official recommendation Axios.
Defining common parameters and introducing components:
Import Axios from ' Axios ' import qs from ' qs ' axios.interceptors.request.use (config => {store.commit (' Update_loadin G ', true]//display loading return co
Perfect solution for cross-origin request errors in axios
Error message:
Response to preflight request doesn't pass access control check: No 'access-Control-Allow-origin' header is present on the requested resource. origin 'HTTP: // localhost: 100' is therefore not allowed access. the response had HTTP status code 403
With the development of the front-end framework, data separation between the front-end and back-end has become a trend. That is to say,
Example of submitting a vue axios form to upload images,
The element framework used in the project, and the requirement for adding data in the project is that images can be uploaded or not uploaded,
The problem is that the upload control in the element does not trigger the submission when there is no image, but the interface writes the multipart/form-data receiving mode with file.
Only one form can be imitated by the other.
Let file = e.tar get.
In the handling of HTTP requests, the use of Vue-resource has been deprecated, but the use of the latest Axios, the following is a simple introduction.InstallationUsing nodeUsing CDNBasic use method GET request//Make a request for a user with a given IDAxios.Get('/user?id=12345'). Then (function (response) {Console.log (response); }) .Catch(function (Error) {Console.log (error); });//optionally the request above could also is done asAxios.Get('/user'
AboutThis project is a vue2 + Element-ui + Axios built back-end management system, adaptive to a variety of screen sizes, all the data is a mock server processing, so just download to run, it is very convenient to replace their REST API interface.Technology stackVue2 + Vuex + vue-router + axios + element-ui + webpack + ES6/7 + SassOpen Source AddressPoint MeDemo AddressPoint MeFor more ANGULAR1/2/4, IONIC1/
‘);}axios.all([getUserAccount(), getUserPermissions()]).then(axios.spread(function(acct, perms) {// ok}));
4, in addition to the Axios also provides the following several request methods:
12345678910111213
axios.request(config)axios.get(url[, config])axios.delete(url[, config]) axios.head(url[, config])axios.post(url[, data[, config]])axios.put(url[, data[, config]])axios.patch(url[, data[, config]])
5. Compatib
Since vue2.0 officially chose Axios to complete the AJAX request, I recently started using Axios to write Ajax requests. The architecture I used before was both front and back, so there was a cross-domain problem. I wrote the Post request method based on Axios's official documentation on GitHub, but the error in the browser console console output cross-domain issues.Server I've done the cross-domain process
Vue-resource use1:CNPM Install Vue-resource--save (in write Package.json)---installation2: Reference in Main.js3: Use directly in Componentsthis. $http. Get (URL). Then (function () {})Axios use1: InstallationCNPM Install Axios--save2: there with references3: Request FormatAxios.get (API). Then (response) = { Console.log (response);}). catch ((Err) =>{ Console.log (ERR);})Fetch-jsonp use1: InstallationNPM
We know that after vue2.0, Vue will not update the Vue-resource, but recommend Axios, and large projects will use VUEX to manage the data, so this blog will be combined to send a request 1. Install AXIOSCNPM I Axios- S2. Scenario One: Modifying the prototype chain first, introduced in Main.js at this time, you still cannot use Axios in the component, but if you c
Laravel5.4 Vuejs and Axios use hooks mounted cannot get property data resolution
Error problem:In then this inside of the assignment method this.followed = response.data.followed will appear error, what reason? The original is then inside cannot be instantiated with Vue, because it is this this not bound internally. Solve:self.followed = response.data.followed;或者使用ES6的箭头函数arrow function,箭头方法可以和父方法共享变量。Here is my code:Data properties:data(){
Axios Delete Requestwhen passing a parameter , put the parameter directly behind the request connection and use '/' to connect.this. Axios.post (this. apiurl+ '/' +id) //http://www.ddd.com/1 . Then (response=>{}) . Catch (error=>{})when you need to pass multiple parameters, delete, after the request interface passed directly with the config, the following wording: this. Axios. Delete (this.) Api. Busine
"No ink directly on the Code series"The code is divided into three steps:1. Create a api.js, package Axios2. Introduced in Main.js and added to the Vue prototype3. Global use1. Create + Package//Api.jsImport Axios from "Axios";varApiurl = ' ';functionYuanajax (url,data,successcallback,errorcallback) {axios.post (Apiurl+ url,data). Then (function(res) {if(typeofSuccesscallback = = ' function ') {successcallb
---again using vue, Axios, formdata do upload files, encountered a problem, although the background received the request, but the file type is recognized as a string , so the web side has been reported 500, the result is their own carelessness.1. Because new Formdata is used to manipulate the form, and when a mock request is being tested, it is indeed the form submission "Content-type:multipart/form-data" that is seen from the header. So there is no i
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.