vue項目中怎樣嵌入其它項目的頁面
vue項目嵌入其它項目的頁面
通過iframe嵌入,src的路徑在static中(vue-cli3在public)配置
編譯打包時,不會將static/public里的文件編譯,前端可修改index.js里的url
方式一
創(chuàng)建index.js,在入口頁面中引入
static/urls/index.js
window.urlsPath = { statisticsUrl: 'http://xx.xx.xx.xx:80' }
入口index.html
// 注意引入js時的路徑 // statis <script src="/static/urls/index.js"></script> // public <script src="./urls/index.js"></script>
statistics.js
<iframe src="url" frameborder="0" width="100%" height="100%"></iframe> created() { this.url = window.urlsPath.statisticsUrl + '#/dataStatistics?userId=' + sessionStorageGet('loginData').userId }
方式二
通過在main.js中請求json文件的方式,拿到url
new Vue({ router, store, render: h => h(App), created() { axios.get('/urls/urls.json').then(res=> { if(res.data.code === '0') { utils.sessionStorageSet('defaultConfig', res.data.data) } }) } }).$mount('#app');
以vue-cli3為例,public/urls/urls.json
{ "code":"0", "data":{ "statisticsUrl": "http://xx.xx.xx.xx:80" } }
vue嵌入本地html頁面
問題描述:
向vue項目中嵌入html頁面
失敗原因:
代碼結構不同,需要放到指定位置
解決:
把本地html、css\js\img都放到與src同級的public\static下
嵌入代碼
<template> <div style="width: 100%"> <!--靜態(tài)html資源--> <div> <iframe src="/static/demo01.html" scrolling="auto" frameborder="0" style="width: 100%;height: 900px;"></iframe> </div> </div> </template>
<script> export default { data() { return { } }, methods: { }, created() { } } </script>
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
vue-create創(chuàng)建VUE3項目詳細圖文教程
create-vue是Vue官方新的腳手架工具,底層切換到了vite(下一代前端工具鏈),為開發(fā)提供極速響應,下面這篇文章主要給大家介紹了關于vue-create創(chuàng)建VUE3項目的相關資料,需要的朋友可以參考下2024-03-03vue實現動態(tài)表格提交參數動態(tài)生成控件的操作
這篇文章主要介紹了vue實現動態(tài)表格提交參數動態(tài)生成控件的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11Vue項目創(chuàng)建首頁發(fā)送axios請求的方法實例
這篇文章主要給大家介紹了關于Vue項目創(chuàng)建首頁發(fā)送axios請求的相關資料,文中通過圖文以及實例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2023-02-02html頁面引入vue組件之http-vue-loader.js解讀
這篇文章主要介紹了html頁面引入vue組件之http-vue-loader.js解讀,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04