-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
232 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# vue3中使用vue2 | ||
|
||
本`demo`展示如何在`vue3`项目中使用`vue2`基站的远程组件 | ||
|
||
# 运行 | ||
```bash | ||
pnpm i | ||
pnpm dev | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "v3u2-demo", | ||
"ignored": true, | ||
"version": "0.0.1", | ||
"scripts": { | ||
"dev": "pnpm --filter 'v3u2-*' --parallel dev", | ||
"build": "pnpm --filter v3u2-* --parallel build", | ||
"serve": "pnpm --filter v3u2-* --parallel serve", | ||
"stat": "pnpm --filter v3u2-* --parallel stat" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "vue2-base", | ||
"name": "v3u2-vue2-base", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
// import Antd from '@v3/Antd' | ||
import {createApp} from 'vue' | ||
import App from './App.vue' | ||
import {router} from './router' | ||
import Home from './home.vue' | ||
// console.log('Antd', Antd) | ||
const app = createApp(App) | ||
const app = createApp(Home) | ||
// app.use(Antd) | ||
app.use(router) | ||
// app.use(router) | ||
app.mount('#emp-root') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
function bindSlotContext(target = {}, context) { | ||
return Object.keys(target).map(key => { | ||
const vnode = target[key]; | ||
vnode.context = context; | ||
return vnode; | ||
}); | ||
} | ||
|
||
/* | ||
* Transform vue2 components to DOM. | ||
*/ | ||
export function vue2ToVue3(WrapperComponent, wrapperId) { | ||
const Vue2 = EMP_ADAPTER_VUE.Vue | ||
const defineAsyncComponent = Vue2.defineAsyncComponent; | ||
let vm; | ||
return { | ||
mounted() { | ||
const slots = bindSlotContext(this.$slots, this.__self); | ||
vm = new Vue2({ | ||
render: createElement => { | ||
return createElement( | ||
WrapperComponent, | ||
{ | ||
on: this.$attrs, | ||
attrs: this.$attrs, | ||
props: this.$props, | ||
scopedSlots: this.$scopedSlots, | ||
}, | ||
slots, | ||
); | ||
}, | ||
}); | ||
vm.$mount(`#${wrapperId}`); | ||
}, | ||
props: WrapperComponent.props, | ||
render() { | ||
vm && vm.$forceUpdate(); | ||
}, | ||
}; | ||
} |
Oops, something went wrong.