Skip to content

Instantly share code, notes, and snippets.

@JorgenVatle
Created March 12, 2019 02:55
Show Gist options
  • Save JorgenVatle/dc2cf00d4cb00e87ac81c1d3f1e48d9d to your computer and use it in GitHub Desktop.
Save JorgenVatle/dc2cf00d4cb00e87ac81c1d3f1e48d9d to your computer and use it in GitHub Desktop.
export default {
name: 'review-reactions',
props: ['agree', 'disagree', 'id'],
template: '<div>' +
' <span v-if="display === \'agree\'">' +
' You and {{ agree }} others disagree to this' +
' </span>' +
' <span v-else-if="display === \'disagree\'">' +
' You and {{ disagree }} others disagree to this' +
' </span>' +
'</div>',
data() {
return {
display: 'none'
}
},
methods: {
/**
* Handle a reaction event.
*
* @note You'd trigger this using window.vue.$emit('react', {YourPostId}, {ReactionType})
* @param postId // This would be your post ID
* @param {'agree'|'disagree'} type
*/
handleReaction(postId, type) {
if (this.id !== postId) {
return;
}
this.display = type;
}
},
created() {
window.vue.$on('react', this.handleReaction)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment