Skip to content
Advertisement

Vue3 onMounted props not defined

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?

Advertisement

Answer

Try this:

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

onMounted(() => {
  console.log(props.configuration);
});
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement