<div id="comment"> <article-content v-bind:article="article"></article-content> <commemt-content v-bind:comment="comment" v-on:change="changCommmer"></commemt-content> <comment-textarea v-bind:type="type" v-bind:name="oldComment" v-on:submit="addComment" v-on:canel="canelCommit"></comment-textarea> </div>
Vue.component('commentTextarea',{
template:'\
<div class="commentBox">\
<h3>发表评论</h3>\
<b v-if="type">你回复 {{name}}</b>\
<textarea name="" value="请填写评论内容" v-model="commentText"></textarea>\
<button class="btn" @click="addComment">发表</button>\
<button class="btn" @click="canelComment">取消</button>\
</div>',
props: ['type','name'],
data: function(){
return {commentText:""}
},
methods: {
addComment: function() {
this.$emit("submit",this.commentText);
this.commentText = "";
},
canelComment: function() {
this.$emit("canel");
this.commentText = "";
}
}
});
comment: [
{
name: "有毒的黄同学", //评论人名字
time: "2016-08-17",
content: "好,讲得非常好,good",
reply: [ //回复评论的信息,是一个数组,如果没内容就是一个空数组
{
responder: "傲娇的", //评论者
reviewers: "有毒的黄同学", //被评论者
time: "2016-09-05",
content: "你说得对"
}
}
]
Vue.component('commemt-content',{
template:'\
<div class="commentBox">\
<h3>评论</h3>\
<p v-if="comment.length==0">暂无评论,我来发表第一篇评论!</p>\
<div v-else>\
<div class="comment" v-for="(item,index) in comment" v-bind:index="index" >\
<b>{{item.name}}<span>{{item.time}}</span></b>\
<p @click="changeCommenter(item.name,index)">{{item.content}}</p>\
<div v-if="item.reply.length > 0">\
<div class="reply" v-for="reply in item.reply">\
<b>{{reply.responder}} 回复 {{reply.reviewers}}<span>{{reply.time}}</span></b>\
<p @click="changeCommenter(reply.responder,index)"">{{reply.content}}</p>\
</div>\
</div>\
</div>\
</div>\
</div>',
props: ['comment'],
methods: {
changeCommenter: function(name,index) {
this.$emit("change",name,index);
}
}
});
var comment = new Vue({
el: "#comment",
data: {
commenter: "session", //评论人,这里会从session拿
type: 0, //0为评论作者1为评论别人的评论
oldComment: null, //久评论者的名字
chosedIndex: -1, //被选中的评论的index
article: {
title: "当归泡水喝的九大功效",
time: "2016-07-12",
read:50,
content: ""
},
comment: [] //评论内容
},
methods: {
//添加评论
addComment: function(data) {
if(this.type == 0) {
this.comment.push({
name: 'session',
time: getTime(),
content: data,
reply: []
});
//服务器端
}else if(this.type == 1){
this.comment[this.chosedIndex].reply.push({
responder: 'session',
reviewers:this.comment[this.chosedIndex].name,
time: getTime(),
content: data
});
this.type = 0;
}
},
//监听到了点击了别人的评论
changCommmer: function(name,index) {
this.oldComment = name;
this.chosedIndex = index;
this.type = 1;
},
//监听到了取消评论
canelCommit: function() {
this.type = 0;
}
}
})
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有