将Vue组件包装为本Web组件。css
因为Angular支持使用自定义Web组件,所以可以使用Vue组件(包装为Web组件)。html
对于Angular,若是自定义Web组件是由Vue生成的,那么它就没有区别(对于全部Angular都知道,它们能够是本机HTML元素)前端
这里使用element-ui做为组件导入angular使用vue
demo地址:https://stackblitz.com/edit/angular-nnbszr
git
index.htmlangularjs
app.module.tsgithub
如今,在angular里,导入Web组件后(即他们Vue的产生与否),其配置为使用加入schemas: [CUSTOM_ELEMENTS_SCHEMA]
你@NgModule
:web
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { AppComponent } from './app.component'; @NgModule({ imports: [ BrowserModule, FormsModule ], declarations: [ AppComponent ], bootstrap: [ AppComponent ], schemas: [ CUSTOM_ELEMENTS_SCHEMA // Added for custom elements support ] }) export class AppModule { }
app.component.htmlelement-ui
如今直接在Angular模板中使用Web组件(从Vue生成或不生成)。例如,上面代码中定义的组件能够像如下同样使用:bootstrap
<h3>Hello, {{ name }}</h3> <p>In index.html, a Vue component is defined using Vue and is wrapped into a Web Component using vue-custom-element.<br> Now, in Angular's template, use it as if it were a native HTML Element (or regular native Web Component). </p> <my-vue-web-comp [msg]="name"></my-vue-web-comp>
有关更多详细信息,请查看vue-custom-element
文档。