Blogger Information
Blog 87
fans 1
comment 0
visits 59147
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
axios的跨域处理
阿杰
Original
1793 people have browsed it

1.下载axios,并在main.js中引入

  1. npm i axios -S
  2. import Axios from 'axios'
  3. Vue.prototype.$axios = Axios //在main.js引入axios,因为其不属于vue全家桶,所以将其挂载在vue原型上,实现全局使用

2.配置config文件中的代理地址

在项目config目录下的修改 index.js文件

  1. proxyTable: {
  2. "/api":{
  3. target: "http://screen.rdxsaj.com",
  4. changeOrigin: true,
  5. pathRewrite: {
  6. '^/api':''
  7. }
  8. }
  9. },

配置完后记得重启项目才会生效

  1. that.$indicator.open({
  2. text:'正在登录...'
  3. })
  4. var obj = {
  5. token:'1AEA4006B1F1F19E26499A75B456EAFD',
  6. deviceSerial:'802883535,D11282193',
  7. appkey:5001,
  8. time:1619071028
  9. }
  10. var url = '/api/v1/vedio';
  11. that.$axios.post(url,obj)
  12. .then(response => {
  13. console.log(response);
  14. setTimeout(function(){
  15. that.$indicator.close();
  16. that.$toast({
  17. message:'登录成功',
  18. // iconClass: 'icon icon-success',
  19. duration:1000
  20. })
  21. },1000);
  22. }).catch(error => {
  23. console.log(error);
  24. })

跨域完成,可以请求到接口了

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post