【发布时间】:2021-07-24 07:30:11
【问题描述】:
我对 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>
这是组件部分
<div v-for="blog in blogs" class="col-md-3">
<div">
<a href="blog-post.html"></a>
<div class="banner">
<div class="banner-bg" v-bind:style="background-image:url('{{ blog.thumbnail }}');"></div>
<div class="banner-caption">
<p class="theme-blog-item-time">day ago</p>
<h5 class="title">{{ blog.title }}</h5>
<p class="desc">{{ blog.desc }}</p>
</div>
</div>
</div>
</div>
这是json中的响应
error: {status: false, msg: ""}
response: {posts: [{id: "44", title: "Andaman Islands: The Complete Guide for Travellers",…},…], totalPages: 2}
posts: [{id: "44", title: "Andaman Islands: The Complete Guide for Travellers",…},…]
0: {id: "44", title: "Andaman Islands: The Complete Guide for Travellers",…}
1: {id: "43", title: "Russia Visa for Indians",…}
2: {id: "42", title: "Dubai Creek – Sail through the heart of Dubai",…}
3: {id: "41", title: "A Must Follow Guide To Japan Visa Requirements",…}
4: {id: "40", title: "Russia to resume issuing visas to all categories of Indian citizens",…}
5: {id: "23", title: "Trapizzino, Rome’s OG Street Food",…}
6: {id: "17", title: "Where to Eat in Rome During Holidays",…}
totalPages: 2
【问题讨论】: