Home > Software engineering >  vue 3 script setup onBeforeMount is not defined
vue 3 script setup onBeforeMount is not defined

Time:01-27

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>

CodePudding user response:

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>

  •  Tags:  
  • Related