Subscribe on changes!

Setup triggers repeatedly when switching components

avatar
Jul 5th 2021

Version

3.1.1

Reproduction link

[https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHRlbXBsYXRlPlxuICA8aDE e3sgbXNnIH19PC9oMT5cbjwvdGVtcGxhdGU XG5cblxuPHNjcmlwdCBsYW5nPVwidHNcIj5cbmltcG9ydCB7IGRlZmluZUNvbXBvbmVudCB9IGZyb20gJ3Z1ZSc7XG5pbXBvcnQgeyB1c2VSb3V0ZXIgfSBmcm9tICd2dWUtcm91dGVyJztcbiAgXG4gIGV4cG9ydCBkZWZhdWx0IGRlZmluZUNvbXBvbmVudCh7XG4gICAgc2V0dXAoKSB7XG4gICAgICBjb25zb2xlLmxvZyhcIkknbSBjb21pbmdcIik7XG4gICAgICBjb25zdCByb3V0ZXIgPSB1c2VSb3V0ZXIoKTtcbiAgICAgIHNldFRpbWVvdXQoKCkgPT4ge1xuICAgICAgICByb3V0ZXIucHVzaCgnLycpXG4gICAgICB9LCAxMDAwKVxuICAgICAgXG4gICAgICByZXR1cm4ge1xuICAgICAgICBtc2c6IFwiXCJcbiAgICAgIH1cbiAgICB9XG4gIH0pXG48L3NjcmlwdD4ifQ==](https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHRlbXBsYXRlPlxuICA8aDE e3sgbXNnIH19PC9oMT5cbjwvdGVtcGxhdGU XG5cblxuPHNjcmlwdCBsYW5nPVwidHNcIj5cbmltcG9ydCB7IGRlZmluZUNvbXBvbmVudCB9IGZyb20gJ3Z1ZSc7XG5pbXBvcnQgeyB1c2VSb3V0ZXIgfSBmcm9tICd2dWUtcm91dGVyJztcbiAgXG4gIGV4cG9ydCBkZWZhdWx0IGRlZmluZUNvbXBvbmVudCh7XG4gICAgc2V0dXAoKSB7XG4gICAgICBjb25zb2xlLmxvZyhcIkknbSBjb21pbmdcIik7XG4gICAgICBjb25zdCByb3V0ZXIgPSB1c2VSb3V0ZXIoKTtcbiAgICAgIHNldFRpbWVvdXQoKCkgPT4ge1xuICAgICAgICByb3V0ZXIucHVzaCgnLycpXG4gICAgICB9LCAxMDAwKVxuICAgICAgXG4gICAgICByZXR1cm4ge1xuICAgICAgICBtc2c6IFwiXCJcbiAgICAgIH1cbiAgICB9XG4gIH0pXG48L3NjcmlwdD4ifQ==)

Steps to reproduce

setup() { console.log('I'm comming'); }

What is expected?

I'm coming

What is actually happening?

I'm coming I'm coming

avatar
Jul 5th 2021

The link is broken

avatar
Jul 5th 2021

The first entry is OK, and V-IF triggers twice

avatar
Jul 5th 2021

I'm not sure what you think is wrong.

  • You initially render the component -> console.log
  • You destroy the component with v-if="false"
  • You render the component again -> console.log - which is correct.

Refreshing the page doesn't change anything about this for me.

avatar
Jul 5th 2021

This is expected behavior. v-if destroys the component and remounts it when toggled back. If you don't want to destroy the component, use v-show.