vue项目中如何嵌入其它项目的页面
通过iframe嵌入,src的路径在static中(vue-cli3在public)配置编译打包时,不会将static/public里的文件编译,前端可修改index.js里的url方式一:创建index.js,在入口页面中引入static/urls/index.jswindow.urlsPath = {statisticsUrl: 'http://xx.xx.xx.x...
·
通过iframe嵌入,src的路径在static中(vue-cli3在public)配置
编译打包时,不会将static/public里的文件编译,前端可修改index.js里的url
方式一:创建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"
}
}
更多推荐
已为社区贡献13条内容
所有评论(0)