在?Vue?中使用?iframe?嵌套頁面的步驟
一、嵌入iframe頁面業(yè)務場景
項目是一個物流運營平臺的管理系統(tǒng),系統(tǒng)中對接了第三方的客服系統(tǒng)。因此這里需要在自己的頁面中嵌入三方客服聊天的頁面(這里對接了智齒)。ps:別問我為什么不自己寫一個聊天的功能,問就是不知道。
二、iframe是什么
ifram標簽規(guī)定了一個內聯(lián)框架,讓我們有可能在當前的HTML文檔中嵌入另外一個文檔,目前所有的主流瀏覽器都支持iframe標簽,當然為了以防萬一你可以在iframe標簽中寫入提示文本,以提示用戶當前使用的瀏覽器不支持iframe。
<iframe src="http://www.baidu.com">
IE:你們都看我干嗎,我現(xiàn)在也是支持的
</iframe>說白了就是我們在一個頁面中嵌入另外一個頁面,一般這個頁面是獨立的。
Vue 中使用 iframe 嵌套頁面
1.在 Vue 中引入 iframe
在 Vue 中使用 iframe 技術需要在組件中引入 iframe 標簽,代碼如下:
<template>
<div>
<iframe src="https://www.baidu.com"></iframe>
</div>
</template>2.設置 iframe 的樣式
在 Vue 中使用 iframe 技術需要設置 iframe 的樣式,包括寬度、高度、邊框等。代碼如下:
<template>
<div>
<iframe src="https://www.baidu.com" width="100%" height="500px" frameborder="0"></iframe>
</div>
</template>3.在 iframe 中嵌套子頁面
在 Vue 中使用 iframe 技術可以嵌套子頁面,代碼如下:
<template>
<div>
<iframe src="./subpage.html" width="100%" height="500px" frameborder="0"></iframe>
</div>
</template>4.在子頁面中設置數(shù)據(jù)傳遞
在 Vue 中使用 iframe 技術可以實現(xiàn)子頁面和父頁面之間的數(shù)據(jù)傳遞,代碼如下:
在子頁面中設置一個按鈕,并在點擊按鈕時向父頁面?zhèn)鬟f數(shù)據(jù):
<template>
<div>
<button @click="sendMessage">發(fā)送消息</button>
</div>
</template>
<script>
export default {
methods: {
sendMessage() {
window.parent.postMessage({ message: 'Hello, parent!' }, '*')
},
},
}
</script>在父頁面中監(jiān)聽子頁面?zhèn)鬟f的數(shù)據(jù),并進行處理:
<template>
<div>
<iframe src="./subpage.html" width="100%" height="500px" frameborder="0" @load="loadIframe"></iframe>
</div>
</template>
<script>
export default {
methods: {
loadIframe() {
const iframe = document.querySelector('iframe')
iframe.contentWindow.addEventListener('message', (event) => {
console.log(event.data.message)
})
},
},
}
</script>以上就是在 Vue 中使用 iframe 技術嵌套頁面的詳細步驟。使用 iframe 技術可以實現(xiàn)多個頁面之間的數(shù)據(jù)傳遞和交互,提高了網(wǎng)站的整體性能和用戶體驗。
到此這篇關于在 Vue 中使用 iframe 嵌套頁面的步驟的文章就介紹到這了,更多相關Vue 使用 iframe 嵌套頁面內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Vue項目Element表格對應字段映射顯示方法:formatter格式化數(shù)據(jù)問題
這篇文章主要介紹了Vue項目Element表格對應字段映射顯示方法:formatter格式化數(shù)據(jù)問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-07-07
Vue+Echarts報錯Cannot?set?properties?of?undefined?(settin
這篇文章主要介紹了Vue+Echarts報錯Cannot?set?properties?of?undefined?(setting?‘plate‘)的問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08
Vue中使用echarts實現(xiàn)繪制人體動態(tài)圖
這篇文章主要為大家詳細介紹了Vue中如何使用echarts實現(xiàn)繪制人體動態(tài)圖,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下2024-03-03
vue 使用 vue-pdf 實現(xiàn)pdf在線預覽的示例代碼
這篇文章主要介紹了vue 使用 vue-pdf 實現(xiàn)pdf在線預覽的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-04-04

