Subscribe on changes!

$attrs only includes `onXXX` when another attribute present

avatar
Jul 17th 2022

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

  1. Use the v-on directive on a component, excluding any other attribute:
<MyButton @click="foo">
  1. In that component, log $attrs in mounted hook.
// MyButton.vue
export default {
  mounted() {
    console.log('MyButton', this.$attrs)
  }
}
  1. Observe the console log shows an empty object.

  2. Add an attribute named foo to the component:

<MyButton @click="sayHi" foo>
  1. Rerun example, and observe the console log shows the onClick handler along with foo.

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

avatar
Jul 17th 2022

Odd. It's working now.