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啦
