Lifecycle Methods

Vue Lifecycle Methods are methods which are called before events. There are 9 events that calls lifecycle methods.

  • onBeforeMount

  • onMounted

  • onBeforeUpdate

  • onUpdated

  • onBeforeUnmount

  • onUnmounted

  • onActivated

  • onDeactivated

  • onErrorCaptured

With vucript, you can write lifecycle functions like normal function.

const lifecycleFunctionName = () => {
    //some actions here
};

Example

import { reactive } from 'Vucript'
const counter:reactive<number> = 0;
const onMounted = ()=>{
    add();
    console.log('mounted!');
}
function add(){
    counter++;
}

This code is compiled to

import { defineComponent, ref, onMounted } from "vue";
export default defineComponent({
  setup() {
    const counter = ref<number>(0);
    const add = function () {
      counter.value++;
    };
    onMounted(() => {
      add();
      console.log("mounted!");
    });
    return { counter, add };
  },
});

Last updated