axios的使用.md
程序员文章站
2022-07-02 16:55:15
...
axios的使用
在本次的项目中使用Vue构建 的项目需要向后台发起请求,Vue本身并不支持发起请求,需要使用vue-sour或者axios等插件,在新版本中对vue-souurce的支持并不友好,我在这里使用了axios,引入的方式有多重,这里只记录通过标签对侵入的方式
引入
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
配置跨域
proxyTable: {
'/ajax': {
target: 'http://cgqsrs.server.com/Duse.aspx',
changeOrigin: true,
pathRewrite: {
'^/ajax': ''
}
}
},
在组件中使用
axios.post('/ajax/Login', {
uname:'test',
pass:"1",
vcode:"asdf"
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});