引入
ts
import {
addEmitsForComponent,
addNameForComponent,
getFullCompName,
getPureCompName,
extractClass,
extractEvent,
extractProps
} from 't-comm';
// 不支持 tree-shaking 的项目
import {
addEmitsForComponent,
addNameForComponent,
getFullCompName,
getPureCompName,
extractClass,
extractEvent,
extractProps
} from 't-comm/lib/component/index';
// 只支持 ESM 的项目
import {
addEmitsForComponent,
addNameForComponent,
getFullCompName,
getPureCompName,
extractClass,
extractEvent,
extractProps
} from 't-comm/es/component/index';addEmitsForComponent(filePath, [fileContent])
描述:
为 Vue 组件添加 emits 属性
参数:
| 参数名 | 类型 | 描述 |
|---|---|---|
| filePath | string | 组件地址 |
| [fileContent] | string | 组件内容 |
返回: string
新的组件内容
示例
ts
addNameForComponent('xxx.vue');addNameForComponent(filePath, componentName)
描述:
为 Vue 组件添加、修正 name 属性
参数:
| 参数名 | 类型 | 描述 |
|---|---|---|
| filePath | string | 组件地址 |
| componentName | string | 组件名称 |
返回: string
新的组件内容
示例
ts
addNameForComponent('xxx.vue', 'PressUploader');getFullCompName(name, prefix)
描述:
获取组件全称
参数:
| 参数名 | 描述 |
|---|---|
| name | 组件名称 |
| prefix | 前缀 |
返回:
全称
示例
ts
getFullCompName('swiper-item', 'press-')
getFullCompName('press-swiper-item', 'press-')
// press-swiper-itemgetPureCompName(name, prefix)
描述:
获取组件简称
参数:
| 参数名 | 描述 |
|---|---|
| name | 组件名称 |
| prefix | 前缀 |
返回:
简称
getPureCompName('press-swiper-item', 'press-')
getPureCompName('swiper-item', 'press-') // swiper-item
extractClass(params)
描述:
提取 Vue 组件的 class
参数:
| 参数名 | 类型 | 描述 |
|---|---|---|
| params | obj | 参数 |
| params.filePath | string | 源文件地址 |
| [params.targetFilePath] | string | 输出文件地址 |
| [params.extractRegexp] | Regexp | 提取正则 |
extractEvent(params)
描述:
提取 Vue 组件的 event
参数:
| 参数名 | 类型 | 描述 |
|---|---|---|
| params | obj | 参数 |
| params.filePath | string | 源文件地址 |
| [params.targetFilePath] | string | 输出文件地址 |
| [params.extractRegexp] | Regexp | 提取正则 |
extractProps(params)
描述:
提取 Vue 组件的 props
参数:
| 参数名 | 类型 | 描述 |
|---|---|---|
| params | obj | 参数 |
| params.filePath | string | 源文件地址 |
| [params.targetFilePath] | string | 输出文件地址 |
| [params.extractRegexp] | Regexp | 提取正则 |