Vue.js 如何在vuejs中使用axios向div显示提取的数据

Vue.js 如何在vuejs中使用axios向div显示提取的数据,vue.js,axios,Vue.js,Axios,我是vue的新手,我正在尝试使用axios api从codeigniter后端获取博客。但我无法理解如何在div中填充它 我使用v-if,它生成了6个列表,但数据不存在,也不知道如何处理背景图像 在json响应中有缩略图:https://url.com/uploads/thumb213.jpg". 如何使用v-bind来显示这一点 <script> new Vue({ el: '#blogapp', data () {

我是vue的新手,我正在尝试使用axios api从codeigniter后端获取博客。但我无法理解如何在div中填充它

我使用v-if,它生成了6个列表,但数据不存在,也不知道如何处理背景图像

在json响应中有缩略图:https://url.com/uploads/thumb213.jpg". 如何使用v-bind来显示这一点

<script>
    new Vue({
        el: '#blogapp',
        data () {
            return {
               blogs: [],
            }
        },
        methods: {
            getBlogs () {
            axios
            .get('https://www.happyvoyaging.com/api/blog/list?appkey="grv250531"')
            .then(response => (this.blogs = response))
            .catch(error => console.log(error))
        },
        },

        mounted() {
           this.getBlogs();
         },
        })
</script>
获取数据
axios.get()

axios.get(/*…*/)。然后(res=>this.blogs=res.data.response.posts)
装订风格
v-bind:style
的绑定值应该是字符串或字符串的JavaScript表达式(例如或字符串串联):

❌
✅

我发现问题在于getBlog函数的then块。您正在这样做。blogs=response。您可以通过response.data.posts从响应中获取数据 只需更换您的:

methods: {
        getBlogs () {
        axios
        .get('https://www.happyvoyaging.com/api/blog/list?appkey="grv250531"')
        .then(response => (this.blogs = response))
        .catch(error => console.log(error))
    },
    },
部分代码如下:

methods: {
        getBlogs () {
        axios
        .get('https://www.happyvoyaging.com/api/blog/list?appkey="grv250531"')
        .then(response => (this.blogs = response.data.posts))
        .catch(error => console.log(error))
    },
    },
应该是这样的

methods: {
        getBlogs () {
        axios
        .get('https://www.happyvoyaging.com/api/blog/list?appkey="grv250531"')
        .then(response => (this.blogs = response))
        .catch(error => console.log(error))
    },
    },
methods: {
        getBlogs () {
        axios
        .get('https://www.happyvoyaging.com/api/blog/list?appkey="grv250531"')
        .then(response => (this.blogs = response.data.posts))
        .catch(error => console.log(error))
    },
    },