-
Notifications
You must be signed in to change notification settings - Fork 12
Angular to Vue 移植指南
Kagol edited this page Feb 27, 2021
·
2 revisions
DevUI/DevUI 组件库:DevUI 官方的 Angular 版本组件库,官网:https://devui.design,源码:https://github.com/devcloudfe/ng-devui。
Vue DevUI/Vue DevUI 组件库:从官方 DevUI 移植出来的 Vue3 版本的 DevUI 组件库。
Vue DevUI 项目只是移植 Angular 版本的 DevUI 组件库,除了 Vue 语法层面的改动之外,不做过多发挥。
Vue DevUI 组件库的 API/Demo 必须保持和 DevUI 组件库的完全一致,目录结构/文件/类/函数命名尽量保持一致,如在移植过程中发现 DevUI 组件库的 BUG 或者不合理之处,请给 DevUI 组件库提 issue。
主要分成两个部分:devui
/src
。
├── devui 组件源码
| ├── button
| ├── ...
| └── style
├── src 官网/组件API/Demo
| ├── app.route.ts
| ├── app.vue
| ├── assets
| ├── components
| └── main.ts
具体Vue语法建议参考Vue官网教程:https://v3.cn.vuejs.org/guide/
button.module.ts
button.component.ts|html|scss
@Component({
selector: 'd-button',
templateUrl: './d-button.component.html',
styleUrls: ['./d-button.component.scss'],
})
export class ButtonComponent {
// 组件生命周期和交互逻辑
}
button.tsx
import { defineComponent } from 'vue'
export default defineComponent({
name: 'd-button',
props: {}, // 输入输出
setup(props, ctx) {
// 组件生命周期和交互逻辑
}
})
</script>
@Input() icon: string; // 输入
@Output() btnClick = new EventEmitter<any>(); // 输出
props: {
icon: {
type: String,
default: '',
},
btnClick: {
type: Function as unknown as () => ((event: MouseEvent) => void)
}
}
<button
[type]="type" // 绑定变量
(click)="onClick($event)" // 绑定事件
>
<span *ngIf="icon"></span> // if逻辑
<ng-content></ng-content> // 内容插槽
</button>
<div [innerHTML]="data.tmw"></div> // 显示HTML内容
<button
type={type}
onClick={onClick}
>
{ icon ? <i></i> : null }
{ ctx.slots.default?.() }
</button>
<div domPropsInnerHTML={data.tmw}></div>
<div className={`devui-accordion-item-title ${ disabled ? 'disabled' : '' }`}></div>
const width = '100px'
<button style={{ width: width, fontSize: '16px' }}></button>
...