Skip to content

Commit 1398982

Browse files
jasper-opsMoonofweisheng
authored andcommitted
feat: ✨ img组件的mode属性增加类型ImageMode
mode有了类型后就不需要再去赋值mode了,直接类型提示+回车
1 parent e6a3b73 commit 1398982

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

docs/component/img.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ mode为小程序原生属性,参考[微信小程序image官方文档](https://
7878
| src | 图片链接 | string | - | - | - |
7979
| width | 宽度,默认单位为px | number / string | - | - | - |
8080
| height | 高度,默认单位为px | number / string | - | - | - |
81-
| mode | 填充模式 | string | 'top left' / 'top right' / 'bottom left' / 'bottom right' / 'right' / 'left' / 'center' / 'bottom' / 'top' / 'heightFix' / 'widthFix' / 'aspectFill' / 'aspectFit' / 'scaleToFill' | 'scaleToFill' | - |
81+
| mode | 填充模式 | ImageMode | 'top left' / 'top right' / 'bottom left' / 'bottom right' / 'right' / 'left' / 'center' / 'bottom' / 'top' / 'heightFix' / 'widthFix' / 'aspectFill' / 'aspectFit' / 'scaleToFill' | 'scaleToFill' | - |
8282
| round | 是否显示为圆形 | boolean | - | false | - |
8383
| radius | 圆角大小,默认单位为px | number / string | - | - | - |
8484
| enable-preview | 是否支持点击预览 | boolean | - | false | - |

src/pages/img/Index.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
<script lang="ts" setup>
4242
import { joy } from '../images/joy'
4343
import img from '../images/jd.png'
44-
const modes = [
44+
import type { ImageMode } from '@/uni_modules/wot-design-uni/components/wd-img/types'
45+
46+
const modes: ImageMode[] = [
4547
'top left',
4648
'top right',
4749
'bottom left',

src/uni_modules/wot-design-uni/components/wd-img/types.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
import { baseProps, makeBooleanProp, makeStringProp, numericProp } from '../common/props'
2+
export type ImageMode =
3+
| 'scaleToFill'
4+
| 'aspectFit'
5+
| 'aspectFill'
6+
| 'widthFix'
7+
| 'heightFix'
8+
| 'top'
9+
| 'bottom'
10+
| 'center'
11+
| 'left'
12+
| 'right'
13+
| 'top left'
14+
| 'top right'
15+
| 'bottom left'
16+
| 'bottom right'
217

318
export const imgProps = {
419
...baseProps,
@@ -14,7 +29,7 @@ export const imgProps = {
1429
/**
1530
* 填充模式:'top left' / 'top right' / 'bottom left' / 'bottom right' / 'right' / 'left' / 'center' / 'bottom' / 'top' / 'heightFix' / 'widthFix' / 'aspectFill' / 'aspectFit' / 'scaleToFill'
1631
*/
17-
mode: makeStringProp('scaleToFill'),
32+
mode: makeStringProp<ImageMode>('scaleToFill'),
1833
/**
1934
* 是否懒加载
2035
*/

0 commit comments

Comments
 (0)