Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(comment like): add comment like function #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/components/Articles/CommentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
</template>

<template slot="actions">
<span @click="commentLike(item.id, item.me.like)">
<LikeOutlined :style="{color: item.me.like ? 'red' : '#8c8c8c'}"/> {{item.likes}}
</span>
<span
v-if="item.user.id===user.id"
:disabled="btnCommentSubmitting"
Expand All @@ -73,7 +76,7 @@
</template>
<comment-list
:id="id" :comments="comments" :pageSize="3" :parent="item.id"/>
</a-comment>
</a-comment>
</a-list-item>
</template>
</a-list>
Expand All @@ -83,9 +86,11 @@
<script>
import axios from 'axios'
import { mapGetters } from 'vuex'
import { LikeOutlined } from '@ant-design/icons-vue'

export default {
name: 'CommentList',
components: { LikeOutlined },
props: ['parent', 'pageSize', 'id'],
data () {
return {
Expand All @@ -104,6 +109,7 @@ export default {
const result = []
this.comments.forEach(item => {
if (item.parent === this.parent) {
item.liked = this.doLikeHaveMe(item.id)
result.push(item)
}
})
Expand Down Expand Up @@ -148,6 +154,20 @@ export default {
await this.$store.commit('updateComments', this.id)
this.commentsLoading = false
})
},
/**
* 点赞评论
*/
commentLike (id, liked) {
if (liked) {
axios.delete('/articles/comments/' + id + '/like').then(async (res) => {
this.$message.success('取消点赞成功')
})
return
}
axios.post('/articles/comments/' + id + '/like').then(async (res) => {
this.$message.success('点赞成功')
})
}
}
}
Expand Down
Loading