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: