How do I call a function in setup() method?

Try this:

<template>
	<div>{{ profile }}</div>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { useRoute } from "vue-router";
export default defineComponent({
	setup() {
		const route = useRoute();

		const getId = () => route.params.id; // 

		let profile = reactive({});

		const getProfile = async () => {
			let profileId = route.params.id;
			const r = await editData.data("/profile", profileId);
			profile = r.data;
		};

		onMounted(() => {
			getProfile();
		});

		return {
			profile, // this will be available in your template
		};
	},
});
</script>
2 Likes