Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
216 views
in Technique[技术] by (71.8m points)

Issues showing the loaded API data using axios in Laravel 8 using Vue.js

I have a Laravel 8 app running with Vue.js. Witch I'm trying to load some data to my project.

I can get the data (also tested when console logging), but when I'm assigning the posts variable, the variable woun't show the data. I see from most example this should work out of the box.

What am I missing here?

<template>
        {{posts}}
</template>

<script>
export default {
    data(){
        return {
            posts: [],
        }
    },
    mounted() {
        this.loadPosts();
    },
    methods:{
        loadPosts: function(){
           axios.get("https://jsonplaceholder.typicode.com/todos")
            .then(response => {
                this.posts = response.data;
            })
            .catch(error => {
                console.log(error);
            });
        }
    }
}
</script>
question from:https://stackoverflow.com/questions/65875111/issues-showing-the-loaded-api-data-using-axios-in-laravel-8-using-vue-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think you should put {{posts}} inside a root div element:

<template>
    <div>{{posts}}</div>
</template>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...