Skip to content

Commit 1adc5b2

Browse files
committed
🚧 增加评论列表的数据接收(来自自己blog的接口)
1 parent b0804ba commit 1adc5b2

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
"build": "node build/build.js"
1515
},
1616
"dependencies": {
17+
"axios": "^0.17.1",
1718
"element-ui": "^2.0.7",
1819
"vue": "^2.5.2",
1920
"vue-amap": "^0.4.4",
21+
"vue-axios": "^2.0.2",
2022
"vue-lazyload": "^1.1.4",
2123
"vue-router": "^3.0.1"
2224
},

src/components/MessageList.vue

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,32 @@
11
<template>
22
<div>
3-
<div class="main" v-for="(todo,index) in comments" v-if="index < 5">
3+
<div class="main" v-for="todo in comments">
44
<div style="margin-bottom: 15px">
55
<div style="display: inline-block">
66
<img src="../assets/head.svg" style="width:35px">
77
</div>
88
<div class="info" style="display: inline-block">
99
<span style="font-size: 15px;color: #333;">{{todo.name}}</span><br/>
10-
<span style="font-size: 12px;color: #969696;">{{comments.length-index+"楼."}}{{todo.create_time|data}}</span>
10+
<span style="font-size: 12px;color: #969696;">{{todo.id+"楼."}}{{todo.create_time|data}}</span>
1111
</div>
1212
</div>
1313
{{todo.content}}
1414
</div>
15-
<div class="block" style="margin-top:30px">
15+
<!-- <div class="block" style="margin-top:30px">
1616
<el-pagination
1717
layout="prev, pager, next"
1818
:total="comments.length/.5"
1919
@current-change="changePage"
2020
:current-page="current">
21-
</el-pagination>
21+
</el-pagination> -->
2222
</div>
2323
</div>
2424
</template>
2525
<script>
2626
export default {
2727
/* eslint-disable */
2828
data() {
29-
let comment = {
30-
name: "白植熙",
31-
content: "测试测试测试测试试测试测试测试测试测试测试测试测试测试测测试测试测试",
32-
create_time: 1512997751,
33-
id: 1
34-
}
35-
let comments = new Array;
36-
for(let i = 0; i < 12; i++){
37-
comments.push(comment)
38-
}
29+
let comments = [];
3930
return {
4031
comments,
4132
current: 1,
@@ -45,8 +36,16 @@ export default {
4536
changePage(val){
4637
console.log(`当前页: ${val}`);
4738
this.current = val;
39+
},
40+
getlist(){
41+
alert('6666')
4842
}
4943
},
44+
beforeCreate: function () {
45+
this.$http("http://www.bai3.xyz/comment/getlist")
46+
.then(response => {console.log(response);this.comments = response.data.reverse()})
47+
},
48+
5049
filters: {
5150
// 时间戳过滤器
5251
data: function (input){

src/main.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import ElementUI from 'element-ui'
66
import 'element-ui/lib/theme-chalk/index.css'
77
import 'element-ui/lib/index.js'
88
import router from './router'
9+
import axios from 'axios'
10+
import VueAxios from 'vue-axios'
911

1012
Vue.config.productionTip = false
1113

12-
Vue.use(ElementUI)
13-
14+
Vue.use(ElementUI, axios, VueAxios)
15+
Vue.prototype.$http = axios
1416
/* eslint-disable no-new */
1517
new Vue({
1618
el: '#app',

0 commit comments

Comments
 (0)