panthro
panthro

Reputation: 24059

Is not a function error when calling async method?

Where am I going wrong with this page file? I just want to call the test method on mounted.

<template>
    <div class="container"></div>
</template>

<script>
export default {
    async test() {
        let result = await axios.get('http://echo.jsontest.com/key/value/one/two');
        console.log(result);
    },
    mounted() {
        this.test();
    }
};
</script>

Upvotes: 0

Views: 271

Answers (1)

Thamer
Thamer

Reputation: 1954

if you want to execute the asyncData, you don't need to use the mounted object method, and you don't even need to use a name function like test

for more information please visit nuxtjs async-data documetion

<template>
    <div class="container"></div>
</template>

<script>
export default {

  async asyncData({ params }) {
        let result = await 
           axios.get('http://echo.jsontest.com/key/value/one/two');
        console.log(result);
    },

};
</script>

Upvotes: 1

Related Questions