Could you advise what is the equivalent of the created()
in the new Vue composition API, which I'm using from within Vue2 like this:
import { reactive, toRefs } from '@vue/composition-api'
From the Composition API docs on Lifecycle Hooks:
Because
setup
is run around thebeforeCreate
andcreated
lifecycle hooks, you do not need to explicitly define them. In other words, any code that would be written inside those hooks should be written directly in thesetup
function.
Anything you would have done in the created
hook you can do in setup
.
If you're coming from Vue 2, you can think of setup
as a combination of data
and created
. This lends itself to elegant patterns in which data can be easily defined through a variety of means like composables, imports, etc. if desired.