mounted() {
//function here
}
<script setup lang="ts">
onMounted(() => {
console.log('component mounted');
});
</script>
//OR
<script lang="ts">
import {defineComponent, onMounted} from 'vue';
export default defineComponent({
onMounted(() => {
console.log('component mounted');
});
});
</script>
created() : since the processing of the options is finished you have access to reactive data properties and change them if you want. At this stage DOM has not been mounted or added yet. So you cannot do any DOM manipulation here
mounted(): called after the DOM has been mounted or rendered. Here you have access to the DOM elements and DOM manipulation can be performed for example get the innerHTML:
mounted() {
//function here
}
<script setup lang="ts">
onMounted(() => {
console.log('component mounted');
});
</script>
//OR
<script lang="ts">
import {defineComponent, onMounted} from 'vue';
export default defineComponent({
onMounted(() => {
console.log('component mounted');
});
});
</script>
created() : since the processing of the options is finished you have access to reactive data properties and change them if you want. At this stage DOM has not been mounted or added yet. So you cannot do any DOM manipulation here
mounted(): called after the DOM has been mounted or rendered. Here you have access to the DOM elements and DOM manipulation can be performed for example get the innerHTML:
mounted() {
//function here
}
<script setup lang="ts">
onMounted(() => {
console.log('component mounted');
});
</script>
//OR
<script lang="ts">
import {defineComponent, onMounted} from 'vue';
export default defineComponent({
onMounted(() => {
console.log('component mounted');
});
});
</script>
created() : since the processing of the options is finished you have access to reactive data properties and change them if you want. At this stage DOM has not been mounted or added yet. So you cannot do any DOM manipulation here
mounted(): called after the DOM has been mounted or rendered. Here you have access to the DOM elements and DOM manipulation can be performed for example get the innerHTML: