How do I get access to my properties with vue3, onMounted
function?
I’m using the setup script
tag:
JavaScript
x
20
20
1
<script lang="ts" setup>
2
import { ref, onMounted, computed, defineEmits, defineComponent } from "vue";
3
4
defineComponent({
5
name: "DatePicker",
6
});
7
8
interface Props {
9
configuration: object;
10
}
11
12
withDefaults(defineProps<Props>(), {
13
configuration: () => ({}),
14
});
15
16
onMounted(() => {
17
console.log(configuration);
18
});
19
</script>
20
configuration
is not defined.
Why is this the case?
Advertisement
Answer
Try this:
JavaScript
1
8
1
let props = withDefaults(defineProps<Props>(), {
2
configuration: () => ({}),
3
});
4
5
onMounted(() => {
6
console.log(props.configuration);
7
});
8