Home > OS >  Vue3 onMounted props not defined
Vue3 onMounted props not defined

Time:06-01

How do I get access to my properties with vue3, onMounted function?

I'm using the setup script tag:

<script lang="ts" setup>
import { ref, onMounted, computed, defineEmits, defineComponent } from "vue";

defineComponent({
  name: "DatePicker",
});

interface Props {
  configuration: object;
}

withDefaults(defineProps<Props>(), {
  configuration: () => ({}),
});

onMounted(() => {
  console.log(configuration);
});
</script>

configuration is not defined.

Why is this the case?

CodePudding user response:

Try this:

let props = withDefaults(defineProps<Props>(), {
  configuration: () => ({}),
});

onMounted(() => {
  console.log(props.configuration);
});
  • Related