知乎个人收藏
栏目总览
{{ description }}
That's all!
{{ modalMessage }}
© 2017 treelake.
Vue.component('my-carousel', {
template: '
})
Vue.component('my-ul', {
template: '
',props: ['items'],
methods: {
changeLimit() {
if (this.limitFrom > this.items.length - this.limitNum) {
this.limitFrom = 0;
} else {
this.limitFrom += this.limitNum;
}
if (this.limitFrom == this.items.length) {
this.limitFrom = 0
}
console.log(this.limitFrom)
},
simpleContent(msg) {
this.$dispatch('child-msg', msg)
// 使用 $dispatch() 派发事件,事件沿着父链冒泡
},
},
data() {
return {
limitNum: 5,
limitFrom: 0,
}
},
events: {
'parent-msg': function () {
this.changeLimit()
}
},
})
Vue.component('my-card', {
template: '
{{ collection.ctitle }}
换一换 ',props: ['collection'],
methods: {
notify: function () {
this.$broadcast('parent-msg')
// 使用 $broadcast() 广播事件,事件向下传导给所有的后代
}
}
})
var shuju, answer;
new Vue({
el: '#app',
data: {
description: '',
visible: false,
// ctitle: '',
allqa: [],
collection: {
'clist': [],
'ctitle': '',
},
left: [],
right: [],
modalMessage: '旧时光回忆完毕!',
modalTitle: 'Welcome!',
rawHtml: ' treelake '
},
methods: {
show() {
this.visible = true;
},
showLeave() {
this.rawHtml = '';
this.modalMessage = '旧时光回忆完毕!';
this.show();
}
},
events: {
'child-msg': function (msg) {
this.$http.jsonp('/find' + msg.answer_url, {}, { // 单文件测试:http://localhost:5000/find
headers: {},
emulateJSON: true
}).then(function (response) {
// 这里是处理正确的回调
answer = response.data;
this.rawHtml = answer.answer;
}, function (response) {
// 这里是处理错误的回调
console.log(response);
});
this.modalMessage = '';
this.modalTitle = msg.title;
this.show();
}
},
ready: function () {
this.$http.jsonp('/collections', {}, { // 单文件测试 http://localhost:5000/collections/
headers: {},
emulateJSON: true
}).then(function (response) {
// 这里是处理正确的回调
shuju = response.data
for (i in shuju) {
this.description += (shuju[i].ctitle + ' ');
// console.log(shuju[i])
}
// this.ctitle = shuju[0].ctitle
// this.collection = shuju[0]
this.allqa = shuju
half = parseInt(shuju.length / 2) + 1
this.left = shuju.slice(0, half)
this.right = shuju.slice(half, shuju.length)
console.log(this.collection)
}, function (response) {
// 这里是处理错误的回调
console.log(response);
});
}
})
#list {
padding: 10px
}
#list li {
margin-bottom: 10px;
padding-bottom: 10px;
}
.jumbotron img {
width: 100%;
}
.author-badge {
width: 38px;
height: 38px;
border-radius: 6px;
display: inline-block;
}
#inner-content img {
width: 100%;
}