本来想把这个页面用jade渲染出来、评论部分用vue,但是想了想觉得麻烦,最后还是整个用vue的组件搞定他吧。
先上在线demo:http://jsbin.com/ceqifo/1/edit?js,output
再上效果图
可直接评论,点击别人的评论能回复别人的评论。
html
<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>
数据全都由根组件绑定下去的。这里还监听了几个事件。
<article-content
是文章内容的组件,没啥好讲的,直接把数据绑定进去子组件就行了。这里我是直接绑定一个obj而不是把标题、时间等等详细的信息分别绑定进去。因为直接绑定一个对象,子组件可以用.
的方式很好的调用,比分开写好多了。
<article-content
组件–文本
然后先说个简单点的,<comment-textarea>
,文本框的那个组件。
Vue.component('commentTextarea',{
template:'\
<div class="commentBox