Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 img 图片组件click事件增加mouseEvent参数 #539

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: 🐛 img 图片组件click事件增加mouseEvent参数
  • Loading branch information
liutao committed Aug 20, 2024
commit 03dfc05920e51c5c5d15bce4661b572135c2db89
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