mirror of
https://github.com/youzan/vant.git
synced 2026-05-10 01:06:44 +08:00
refactor: reorganize all components (#8303)
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
/**
|
||||
* Create a basic component with common options
|
||||
*/
|
||||
import { App, defineComponent, ComponentOptionsWithObjectProps } from 'vue';
|
||||
import { camelize } from '../format/string';
|
||||
|
||||
export function createComponent(name: string) {
|
||||
return function (sfc: ComponentOptionsWithObjectProps) {
|
||||
sfc.name = name;
|
||||
sfc.install = (app: App) => {
|
||||
app.component(name as string, sfc);
|
||||
app.component(camelize(`-${name}`), sfc);
|
||||
};
|
||||
|
||||
return defineComponent(sfc);
|
||||
} as typeof defineComponent;
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
import { createBEM } from './bem';
|
||||
import { createComponent } from './component';
|
||||
import { createTranslate } from './translate';
|
||||
|
||||
export function createNamespace(name: string) {
|
||||
name = 'van-' + name;
|
||||
return [
|
||||
createComponent(name),
|
||||
createBEM(name),
|
||||
createTranslate(name),
|
||||
] as const;
|
||||
return [name, createBEM(name), createTranslate(name)] as const;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export * from './base';
|
||||
export * from './create';
|
||||
export * from './installable';
|
||||
export * from './format/unit';
|
||||
export * from './format/number';
|
||||
export * from './format/string';
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { App } from 'vue';
|
||||
import { camelize } from './format/string';
|
||||
|
||||
export function installable<T>(options: T) {
|
||||
return {
|
||||
...options,
|
||||
install(app: App) {
|
||||
const { name } = options as any;
|
||||
app.component(name, options);
|
||||
app.component(camelize(`-${name}`), options);
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user