Skip to content

Commit

Permalink
fix: 🐛 img 图片组件click事件增加mouseEvent参数
Browse files Browse the repository at this point in the history
  • Loading branch information
liutao committed Aug 20, 2024
1 parent febe730 commit 03dfc05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/component/img.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ mode为小程序原生属性,参考[微信小程序image官方文档](https://

| 事件名称 | 说明 | 参数 | 最低版本 |
| -------- | -------------------- | ----------------- | -------- |
| click | 点击事件 | - | - |
| click | 点击事件 | (event: MouseEvent) => void | - |
| load | 当图片载入完毕时触发 | `{height, width}` | - |
| error | 当错误发生时触发 | `{errMsg}` | - |

Expand Down
10 changes: 7 additions & 3 deletions src/uni_modules/wot-design-uni/components/wd-img/wd-img.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import { addUnit, isDef, objToStyle } from '../common/util'
import { imgProps } from './types'
const props = defineProps(imgProps)
const emit = defineEmits(['error', 'click', 'load'])
const emit = defineEmits<{
(e: 'error', event: Event): void
(e: 'click', event: MouseEvent): void
(e: 'load', event: Event): void
}>()
const rootStyle = computed(() => {
const style: Record<string, string | number> = {}
Expand All @@ -57,13 +61,13 @@ function handleError(event: Event) {
status.value = 'error'
emit('error', event)
}
function handleClick() {
function handleClick(event: MouseEvent) {
if (props.enablePreview && props.src) {
uni.previewImage({
urls: [props.src]
})
}
emit('click')
emit('click', event)
}
function handleLoad(event: Event) {
status.value = 'success'
Expand Down

0 comments on commit 03dfc05

Please sign in to comment.