Axios of VUE projects based on VUE-CLI 2--most basic requests

Source: Internet
Author: User

Sorry, the following request of the link, I will hide the domain name, so want to try to find a friend trouble themselves for a new test, I'm sorry



Cross-domain is also configured below

1.config/index.js configuration: Troubleshooting cross-domain dev: {env:require ('./dev.env '), port:8008, Autoopenbrowser:false, Assetssubdirector Y: ' Static ', Assetspublicpath: '/', proxytable: {'/ajaxurl ': {target: ' https://www.aaaaaaa.com/', Changeo Rigin:true, Pathrewrite: {' ^/ajaxurl ': '/'}}} 2.main.js configuration: Use Axios: Note Line 25th, add it to the prototype chain instead of using U
Se method import Vue from ' Vue ' import App from './app ' import Axios from ' Axios ' Vue.prototype. $http =axios; New Vue ({el: ' #app ', render:h => H (APP)}) 3.app.vue: Invoke Ajax: Line 45th, Axios support Promise method, so write convenient point <template> <di V id= "App" > huoqu <button @click = "Myajax" > Get home Information </button> </div> </template> <script&gt
	; Export Default {name: ' app ', components: {}, Data:function () {}, methods: {myajax:function () {this. $ht
				Tp.get ("/ajaxurl/welfare/gpa/index/index"). Then (response => {console.log ("success in Obtaining Information") Console.log (response); }, Response => {Console.log ("Get information Failed") Console.log (response); }}}} </script> <style> </style>
The final effect is this:

This is the most basic, relatively simple, we can try

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.