$attrs only includes `onXXX` when another attribute present
Vue version
3.2.37
Link to minimal reproduction
https://stackblitz.com/edit/vue3-script-setup-with-vite-ylwios?file=src%2Fcomponents%2FAA.vue
Steps to reproduce
- Use the
v-on
directive on a component, excluding any other attribute:
<MyButton @click="foo">
- In that component, log
$attrs
inmounted
hook.
// MyButton.vue
export default {
mounted() {
console.log('MyButton', this.$attrs)
}
}
Observe the console log shows an empty object.
Add an attribute named
foo
to the component:
<MyButton @click="sayHi" foo>
- Rerun example, and observe the console log shows the
onClick
handler along withfoo
.
What is expected?
$attrs
contains the onClick
(and other v-on
directive values) without requiring any other unrelated attribute
What is actually happening?
$attrs
is an empty object unless another attribute exists
System Info
System:
OS: Linux 5.0 undefined
CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.10 - /bin/yarn
npm: 7.17.0 - /bin/npm
npmPackages:
vue: ^3.2.37 => 3.2.37
Any additional comments?
No response