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

Using the camelCased event in the CDN cannot be triggered #2277

Closed
xuliangzhan opened this issue Sep 30, 2020 · 8 comments
Closed

Using the camelCased event in the CDN cannot be triggered #2277

xuliangzhan opened this issue Sep 30, 2020 · 8 comments

Comments

@xuliangzhan
Copy link

xuliangzhan commented Sep 30, 2020

Version

3.0.0

Reproduction link

https://jsfiddle.net/xcr4aLvy/

Steps to reproduce

CDN mode events cannot be triggered because HTML is not case sensitive

What is expected?

You want it to be triggered by the kebab-case event

What is actually happening?

The event cannot be triggered normally

@edison1105
Copy link
Member

modify your code:
emits: ['myclick']
and
emit('myclick', e)

worked.

@xuliangzhan
Copy link
Author

modify your code:
emits: ['myclick']
and
emit('myclick', e)

worked.

Because Props can support the camelCased & kebab-case.

props:{ showContent: String }
emits: ['myClick']
emit('myClick', e)
and
:show-content="xxx"
@my-click="xx"

It would be great if event could support kebab-case.

@edison1105
Copy link
Member

image

Maybe it's a bug.props key is onMyclick and handlerName is onMyClick.they do not match. I think we should use same way to convert them to keep them matched. @posva

@edison1105
Copy link
Member

edison1105 commented Sep 30, 2020

modify your code:
emits: ['myclick']
and
emit('myclick', e)
worked.

Because Props can support the camelCased & kebab-case.

props:{ showContent: String }
emits: ['myClick']
emit('myClick', e)
and
:show-content="xxx"
@my-click="xx"

It would be great if event could support kebab-case.

recommended usage:
<child-demo @my-click="myEvent2"></child-demo>
emits: ['my-click']
emit('my-click', e)

@xuliangzhan
Copy link
Author

modify your code:
emits: ['myclick']
and
emit('myclick', e)
worked.

Because Props can support the camelCased & kebab-case.
props:{ showContent: String }
emits: ['myClick']
emit('myClick', e)
and
:show-content="xxx"
@my-click="xx"
It would be great if event could support kebab-case.

recommended usage:
<child-demo @my-click="myEvent2"></child-demo>
emits: ['my-click']
emit('my-click', e)

Thank you for your reply.That's the way I use it now, but writing the event names for the render functions is a little bad.
<child-demo @my-click="myEvent2"></child-demo>
emits: ['my-click']
emit('my-click', e)

h(ChildDemo, {
  'onMy-click'(){}
})

😄Expect events to support both camelCased & kebab-case.

@edison1105
Copy link
Member

edison1105 commented Sep 30, 2020

because we must use the converted event name in render function.

@shadowings-zy
Copy link
Contributor

It seems not a bug, but a feature. See setFullProps function in packages/runtime-core/src/componentProps.ts file.

function setFullProps(
  instance: ComponentInternalInstance,
  rawProps: Data | null,
  props: Data,
  attrs: Data
) {
  const [options, needCastKeys] = instance.propsOptions
  if (rawProps) {
    for (const key in rawProps) {
      const value = rawProps[key]
      // key, ref are reserved and never passed down
      if (isReservedProp(key)) {
        continue
      }
      // prop option names are camelized during normalization, so to support
      // kebab -> camel conversion here we need to camelize the key.
      let camelKey
      if (options && hasOwn(options, (camelKey = camelize(key)))) {
        props[camelKey] = value
      } else if (!isEmitListener(instance.emitsOptions, key)) {
        // Any non-declared (either as a prop or an emitted event) props are put
        // into a separate `attrs` object for spreading. Make sure to preserve
        // original key casing
        attrs[key] = value
      }
    }
  }

  if (needCastKeys) {
    const rawCurrentProps = toRaw(props)
    for (let i = 0; i < needCastKeys.length; i++) {
      const key = needCastKeys[i]
      props[key] = resolvePropValue(
        options!,
        rawCurrentProps,
        key,
        rawCurrentProps[key],
        instance
      )
    }
  }
}

Any non-declared (either as a prop or an emitted event) props are put into a separate attrs object for spreading. Make sure to preserve original key casing.

@posva
Copy link
Member

posva commented Sep 30, 2020

See #2249

@posva posva closed this as completed Sep 30, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Nov 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants