Reputation: 568
I want to run a event before content load. I do it on Vue 3 option API wiht created() lifecycle hook but Now, I do it with Vue 3 Composition API.
Code:
<script setup>
import { created } from "vue";
const initDark = created(() => {
console.log("init");
});
</script>
When I use it then show a console error.
How can i solve this.
I try below code but it didn't work as expected and it generate a console error.
<script setup>
import { created } from "vue";
const initDark = created(() => {
console.log("init");
});
</script>
Upvotes: 0
Views: 361
Reputation: 1101
No, Vue3 Composition API does not include a lifecycle method named created
. This is because created
has been replaced with setup
.
You can write console.log("init");
at the top-level.
tip: if you want to include a lifecycle hook like mounted
, import onMounted
instead of mounted
:
import { onMounted } from 'vue';
onMounted(() => {
console.log('This is onMounted hook');
});
Upvotes: 2