vue 3 script setup onBeforeMount is not defined
Asked Answered
I

1

5

Hello today i move to vue 3 with script setup.

I try use onBeforeMount for load external data (async await).

but receive error: "onBeforeMount is not defined"

I going to documentation and saw that onBeforeMount should work! what is problem ? enter image description here

<script setup>
import { ref } from '@vue/reactivity';
import axios from 'axios';

var data = ref(null);

onBeforeMount(async () => {
    data.value = await axios.get("url");
})
</script>
Ilyssa answered 26/1, 2022 at 21:35 Comment(1)
Show us your code ;).Frontal
E
11

It seems that you've missed to import it from vue :

<script setup>
import { ref} from '@vue/reactivity';

import {onBeforeMount } from 'vue'
import axios from 'axios';

var data = ref(null);

onBeforeMount(async () => {
    data.value = await axios.get("url");
})
</script>

Edouard answered 26/1, 2022 at 21:43 Comment(2)
oh.... stupid ide always all auto importing but now... thx its work. Right import is "from '@vue/runtime-core';"Ilyssa
just import all the hooks and reactivity properties from 'vue'Edouard

© 2022 - 2024 — McMap. All rights reserved.