利用for循环写出新浪页面思路:
注意:
代码如下:
<script src="./sina.js">script>
<script src='https://cdn.jsdelivr.net/npm/vue/dist/vue.js'>script>
head>
<body>
<style>
.box{
width: 700px;
background-color: rgb(217, 225, 225);
border-radius: 10px;
padding-bottom: 30px;
margin: 30px auto;
}
.title{
width: 100%;
padding: 10px;
display: flex;
justify-content: flex-start;
}
.title img{
width: 50px;
height: 50px;
/* margin-right: 20px; */
border-radius: 50%;
}
#content{
width: 650px;
padding: 20px;
}
.title .no{
width: 10px;
height: 10px;
border-radius: 50%;
background-color: darkred;
}
.title .yes{
width: 10px;
height: 10px;
border-radius: 50%;
background-color: chartreuse;
}
.imgs{
width: 600px;
display: flex;
justify-content: flex-start;
flex-wrap: wrap;
margin-left: 50px;
}
.imgs img{
width: 200px;
height: 200px;
}
style>
<div id='app'>
<div v-for="el in statuses" class="box">
<div class="title">
<img :src="el.user.profile_image_url">
<div :class="{yes:el.user.online_status,no:true}">div>
<p>{{el.user.name}}p>
div>
<p id="content">{{el.text}}p>
<div class="imgs">
<img v-for="el2 in el.pic_urls" :src="el2.thumbnail_pic">
div>
div>
div>
<script>
console.log(obj)
new Vue({
el:'#app',
data:obj,
})
script>
效果图:
添加时间:
<span style="margin-left:20px;color: aliceblue;"{{el.created_at|tool}}span>
new Vue({
el: '#app',
data: obj,
filters:{
tool(str){
var time=(new Date().getTime()-new Date(str).getTime())/6000
if(time>=0&&time<1){
return "刚刚"
} else if(time>=1&&time<60){
var times=new Date(time).getMinutes()
return `${times}分钟前`
}else {
var time2=new Date(time).getHours()
return `${time2}小时前`
}
}
}
})
script>