mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
types(Badge): improve typing
This commit is contained in:
parent
d86238f071
commit
1b96a45d0b
@ -2,13 +2,18 @@ import { isDef, createNamespace } from '../utils';
|
|||||||
|
|
||||||
const [createComponent, bem] = createNamespace('badge');
|
const [createComponent, bem] = createNamespace('badge');
|
||||||
|
|
||||||
|
export type BadgeProps = {
|
||||||
|
dot?: boolean;
|
||||||
|
badge?: number | string;
|
||||||
|
};
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
props: {
|
props: {
|
||||||
dot: Boolean,
|
dot: Boolean,
|
||||||
badge: [Number, String],
|
badge: [Number, String],
|
||||||
},
|
},
|
||||||
|
|
||||||
setup(props) {
|
setup(props: BadgeProps) {
|
||||||
return () => {
|
return () => {
|
||||||
const { dot, badge } = props;
|
const { dot, badge } = props;
|
||||||
const hasBadge = isDef(badge) && badge !== '';
|
const hasBadge = isDef(badge) && badge !== '';
|
@ -2,16 +2,16 @@
|
|||||||
* Create a basic component with common options
|
* Create a basic component with common options
|
||||||
*/
|
*/
|
||||||
import { camelize } from '../format/string';
|
import { camelize } from '../format/string';
|
||||||
import type { App, ComponentOptions } from 'vue';
|
import { App, defineComponent, ComponentOptionsWithObjectProps } from 'vue';
|
||||||
|
|
||||||
export function createComponent(name: string) {
|
export function createComponent(name: string) {
|
||||||
return function (sfc: ComponentOptions) {
|
return function (sfc: ComponentOptionsWithObjectProps) {
|
||||||
sfc.name = name;
|
sfc.name = name;
|
||||||
sfc.install = (app: App) => {
|
sfc.install = (app: App) => {
|
||||||
app.component(name as string, sfc);
|
app.component(name as string, sfc);
|
||||||
app.component(camelize(`-${name}`), sfc);
|
app.component(camelize(`-${name}`), sfc);
|
||||||
};
|
};
|
||||||
|
|
||||||
return sfc;
|
return defineComponent(sfc);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user