Vue's Learning Path vue-cli and Axios

Source: Internet
Author: User

1, build a vue-cli to build a project

(1) Installation vue-cli

NPM Install Vue-cli-g

(2) Vue init webpack project name

Select Settings as needed

(3) NPM Install

Install the configuration (be aware that the current location is in the project if the configuration is installed, otherwise it will be error: Configuration file Package.json not found)

(4) npm run dev

Run locally

2. Data transfer with Axios and back end

(1) Installation Axios

NPM Install Axios

(2) Introduction of Axios in Main.js

Import Axios form ' Axios '

(3) Hang the Axios in the Vue.prototype. $http

Vue.prototype. $http = Axios;

(4) Modify the configuration in Config/index.js, define global variables, set the cross-domain state

Dev: {

Paths
Assetssubdirectory: ' Static ',
Assetspublicpath: '/',
Proxytable: {
'/api ': {
Target: ' Https://www.baidu.com/public ',
Changeorigin:true, //local creation of a virtual server side, the server and the server to interact with the data will not have cross-domain issues
Pathrewrite: {
' ^/api ': ' //replace the requested address in the Targe
}
}
},

(5) Access interface
this. $http. Post ('/api/login ',
{
Name: "Admin",
Password: "123456"
})
. Then (function (response) {
Console.log (response);
})
. catch (function (error) {
Console.log (Error);
});
(6) To restart after configuring the Index.js.

Vue's Learning Path vue-cli and Axios

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.