Trigger a function on page load (solved)
-
Hi everybody, I’m trying to trigger a function (or a method) (for instance an axios request) when the page is loaded. I tried with computed or mounted but it doesn’t work.
-
you can call your method from created or mounted. it should work, you can use console.log() to check that function is called or not.
-
@sujan-dev I tried but it didn’t work. Nothing appeared.
-
@mattiabilla can you share your code
-
Hi @mattiabilla ,
Just to be sure, did you do it like that ?
<script> export default { data () {}, methods: { myFunction () { console.log('Hi my name is myFunction') } }, created () { this.myFunction() } } </script>
Hope it will help
-
@sweetyy This works perfectly. Thanks