Subscribe on changes!

changes to $attrs don't trigger options API watcher

avatar
Jul 4th 2021

Version

3.1.4

Reproduction link

https://jsfiddle.net/Lg38t5qh/18/

Steps to reproduce

  • create component
  • watch $attrs

What is expected?

$attrs watcher is triggered on attributes change

What is actually happening?

$attrs watcher is not triggered

avatar
Jul 4th 2021

you need a deep: true watcher, because the value of $attrs doesn't change - it's the same object - only a property on that object changes

avatar
Jul 4th 2021

@LinusBorg this behavior differs from Vue2 :) Probably should note that at least for compat build :)

avatar
Jul 4th 2021

Hm, indeed. I'll open it for now as I'm not sure from the top of my head wether that was intentional etc.

avatar
Jul 4th 2021

I would say this is an improvement over Vue 2

avatar
Jul 4th 2021

The thing is, it's inconsistent. Vue 3 does trigger watch callbacks when provided a normal object. Like Vue 2. But for $attrs it doesnt work.

avatar
Jul 4th 2021

It does with a reactive object but $attrs is not a reactive object (https://v3.vuejs.org/guide/composition-api-setup.html#context). Maybe something to add for compat build if possible