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'
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
setupis run around thebeforeCreateandcreatedlifecycle 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 thesetupfunction.
Anything you would have done in the created hook you can do in setup.
to help the community, the created() method can be used this way. hope this helps :)
<script>
import TenantsAPI from "@/api/tenants";
export default {
setup() {
const tenantsAPI = new TenantsAPI(); //compositon api
};
}
//options api
//async created(){
// this.tenantsAPI = new TenantsAPI();
//}
</script>