</div>
<div v-if="puzzle.type === 'native'">
<div v-append="puzzle.content" :style="'width:100%;height:' + puzzle.height"></div>
</div>
</div>
</div>
<script>
const content=`<h1>前端开发迭代计划</h1><table class="table table-bordered table-striped table-hover"><tr><th>序号</th><th>需求</th><th>优先级</th><th>负责人</th><th>计划完成日期</th></tr><tr><td>1</td><td>大数据的自助分析平台</td><td>高</td><td>工程师A</td><td>2020-04-08</td></tr><tr><td>2</td><td>自定义模板、调用时传入XML,引擎生成报表结果</td><td>高</td><td>工程师A</td><td>2020-04-08</td></tr></table>`
const puzzles = [
{ id: 1, type: 'module', url: 'http://localhost:9081/list.js',width: '100%',height: '400px'},
{ id: 2, type: 'native', content: content, width: '50%', height: '400px'},
{ id: 3, type: 'iframe', src: 'http://cn.bing.com/',width: '50%',height: '400px'},
]</script>
iframe嵌入
iframe嵌入是是目前大多数人使用的方式,基本没有开发量。
原生html嵌入
这种方式外部接口提供html文本,本地系统划一块地方出来给你自己渲染,如划一个600×800的div用来渲染报表。使用vue-append作为渲染组件。这种方式可以摆脱iframe,自由度也比较大。缺点是不容易实现规范化,有点像内嵌的广告页面。
模块化嵌入
使用模块打包的概念,通过webpack将子模块各个分拆独立打包成模块再通过静态文件方式加载到外部系统做展现。这也是目前团队内部使用的方案。通过遍历模块目录(一般就是业务vue页面)批量生成配置文件。
....... function readDirectory(directory) {
fs.readdirSync(directory).forEach((file) => {
const fullPath = path.resolve(directory, file);
if (fs.statSync(fullPath).isDirectory()) {
if (scanSubDirectories) readDirectory(fullPath);
return;
}
if (!regularExpression.test(fullPath)) return;
//files[directory.substring(directory.lastIndexOf(path.sep))+ path.sep +file] = fullPath
files[directory.substring(parentPath.length+1)+ path.sep +file] = fullPath
//console.log(files)
});
}
.......
最终就会按模块输出打包好的js文件,发布是可以实现按需集成。

到此这篇关于基于Vue实现微前端的文章就介绍到这了,更多相关基于Vue实现微前端内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!










