把一个Vue项目的页面打包后再另一个项目中使用

步骤:

1.项目1新建一个js文件,引入我们需要使用的vue页面:

复制代码
// 引入组件
import indexVue from './index.vue'

// install
indexVue.install = function (Vue) {
  Vue.component("indexVue", indexVue)
  // Vue.component(FlowEditorVue.name, FlowEditorVue)
}


// 导出
export default indexVue

2.在项目1的package.json中添加命令将刚才导出的vue页面进行打包;

复制代码
"lib": "vue-cli-service build --mode prod --target lib --name indexVue --dest lib src/views/workflow/work/index.js"

3.在你需要使用的项目中将打包后的lib目录放在项目2的public目录下;

4.然后再项目2的main.js文件中引入我们lib中的common.js并使用它;

复制代码
import indexVue from '../public/lib/indexVue.common.js'
Vue.use(indexVue)

5.再我们的项目2的页面中直接使用它;

复制代码
<template>
  <div class="app-container">
    <index-vue></index-vue>
  </div>
</template>
<script>

export default {
  name: 'WorkProcess',

  data() {
    return {}

  },
}
</script>

<style scoped>

</style>
相关推荐
Pu_Nine_925 分钟前
10 分钟上手 ECharts:从“能跑”到“生产级”的完整踩坑之旅
前端·javascript·echarts·css3·html5
東雪蓮☆1 小时前
从零开始掌握 Web 与 Nginx:入门详解
运维·服务器·前端·nginx
脑子慢且灵1 小时前
【JavaWeb】一个简单的Web浏览服务程序
java·前端·后端·servlet·tomcat·web·javaee
柯南二号1 小时前
【大前端】 断点续传 + 分片上传(大文件上传优化) 的前端示例
前端
前端小超超1 小时前
如何配置capacitor 打包的安卓app固定竖屏展示?
android·前端·gitee
xiaopengbc2 小时前
在Webpack中,如何在不同环境中使用不同的API地址?
前端·webpack·node.js
前端AK君2 小时前
React中台系统如何嵌入到业务系统中
前端
Slice_cy2 小时前
不定高虚拟列表
前端
m0_748461392 小时前
Spring Boot + Vue 项目中使用 Redis 分布式锁案例
vue.js·spring boot·redis
前端AK君2 小时前
React组件库如何在vue项目中使用
前端