Use 6--configuration for Axios of Vue projects based on VUE-CLI Axios

Source: Internet
Author: User

Sometimes need to write a long path, annoying, so you can write the same operation together, if you need to modify, you can modify the Axios request


Like BaseURL: ' https://www.baidu.com ',

1. Configure Config/index.js: Troubleshoot cross-domain issues dev: {env:require ('./dev.env '), port:8008, Autoopenbrowser:false, Assetssubdirector Y: ' Static ', Assetspublicpath: '/', proxytable: {'/ajaxurl ': {target: ' https://www.aaaaaaaa.com/', change Origin:true, Pathrewrite: {' ^/ajaxurl ': '/'}}} 2.main.js: Configure Axios to prototype chain, note Line 25th, configure Axios settings, note
26 to 29 lines import Vue from ' Vue ' import App from './app ' import Axios from ' Axios ' Vue.prototype. $http =axios;
Axios.defaults.baseURL = '/ajaxurl/welfare/gpa/'; axios.defaults.timeout=1000,///default contenttype for JSON and UTF-8; axios.defaults.headers={' content-type ': ' text/html; charset=gb2312 '} new Vue ({el: ' #app ', render:h => H (APP)}) 3.app.vue: Use request, get for example, do not need to write a long address, the final integration of the project when the change can be!soeasy,
No longer worry about cross-domain problems. <template> <div id= "app" > huoqu <button @click = "Myajax" > Get home Information </button> </div> </te Mplate> <script> Export Default {name: ' app ', components: {}, Data:function () {}, methods: {myajax:function () {this. $http ({method: ' Get ', url: '/brand/list ', data: {page:1,
						Size:10},}). Then (response => {console.log ("successful Request");
					Console.log (response);
						}, Response => {console.log ("request Failed");
					Console.log (response); })},}} </script> <style> </style>
Effect:



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.