用vue-resource调用api的数据,我把他们放在一个数组里面,然后写在在标签不能显示数据
1.用vue-resource调用api的数据,我把他们放在一个数组里面,然后写在在标签不能显示数据
2.<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="css.css">
<style>
body,ul,li{
padding:0;
margin:0;
}
#box{
width: 640px;
padding-top: .7rem;
-webkit-transition: all .3s ease;
transition: all .3s ease;
background-color: #f2f2f2;
margin:50px auto;
clear: both;
}
.li{
padding-top: .3rem;
margin-top: .2rem;
width: 640px;
background-color: #fff;
list-style: none;
}
.Bbox{
width: 640px;
}
.up{
width: 640px;
height: 80px;
-webkit-box-align: start;
align-items: flex-start;
padding: 0 .2rem;
clear: both;
}
.up .icon{
float: left;
height: 80px;
width: 80px;
margin-right: .3rem;
background:url("logo.jpg");
background-size: 100%;
border-radius: 100%;
}
.contend{
float: left;
height: 80px;
margin:0 20px;
}
.contend span{
display: inline-block;
color:
border:1px solid #ccc;
}
.contend .name{
color: #f60;
font-size: 18px;
}
.contend .borderl{
color: #1abc9c;
font-size: 18px;
padding: 2px;
border: 1px solid #1abc9c;
margin:0 20px;
}
.contend .borderr{
color: #1abc9c;
font-size: 18px;
padding: 2px;
border: 1px solid #1abc9c;
}
.contend p{
color: #999;
font-size: 20px;
}
.center{
padding: 0 .2px;
color: #333;
font-size: 26px;
border-bottom: 1px solid #ccc;
}
.center a{
text-decoration: none;
color: #000;
}
.down{
width: 640px;
}
.down div{
width: 33%;
float: left;
line-height: 72px;
text-align: center;
color: #929292;
font-size: 22px;
}
</style>
</head>
<body>
<div id="app">
<demo-grid v-for="infoList in infoLists" ></demo-grid>
<div ></div>
</div>
<!-- 定义组件 -->
<script type="text/x-template" id="grid-template">
<div id="box">
<ul>
<li class="li">
<div class="Bbox">
<div class="up">
<div class="icon"></div>
<div class="contend">
<span class="name"></span>
<span class="borderl"> 置顶</span>
<span class="borderr"> 分享</span>
<p >一个月前</p>
</div>
</div>
<div class="center"><a href="" ><p >{{infoList.title}}</p></a></div>
<div class="down">
<div class="cai"><i class="iconfont"></i>13916</div>
<div class="read"><i class="iconfont"></i>99</div>
<div class="share"><i class="iconfont"></i>分享</div>
</div>
</div>
</li>
</ul>
</div>
</script>
<script src="vue.js"></script>
<script src="vue-resource.js"></script>
<!-- 注册组件 -->
<script>
window.onload=function(){
Vue.component('demo-grid',{
template:"#grid-template",
})
new Vue({
el:'#app',
data:{
infoLists:[],
},
ready:function(){
console.log(this)
// this.getData();
this.$http.get('https://cnodejs.org/api/v1/topics').then((response) => {
// this.infoLists = response.data
console.log(response.data.data)
this.$set('infoLists',response.data.data)
// console.log(response)
}, (response) => {
// error callback
});
},
})
}
</script>
<!-- 取数据 -->
</body>
</html>
3.{{infoList.title}}无效
4.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论