vue项目中嵌套了iframe标签,在iframe获取后台接口的时候报错,未登录,原因是找不到cookie。

  

<iframe :src='urlSrc' width='100%' height='500px'  id='content'></iframe>
this.urlSrc = `http://192.168.1.21:8080/gismap/?${document.cookie}`

然后在你iframe那个页面的js中获取到cookie

var cookie = window.location.search.slice(1)

获取到之后加入到ajax的请求头中

$.ajax({
   url:'后台接口路径',
   type:'post',
   data:{},
   dataType:'JSON',
   headers:{'Authorization':cookie},
   success:function(data){console.log(data)},
   error:function(error){console.log(error)}    
}) 

这样传过去之后就OK啦

相关文章:

  • 2021-06-08
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-11
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2021-09-01
相关资源
相似解决方案