VUE EASY COMMENTS

The easiest way to add comment functionality in your VUE application

Dependencies

  • Axios : ^1.3.4
  • vue : ^3.2.13

Installation

$ npm install @kengo98/vue-easy-comments

OR

$ yarn add @kengo98/vue-easy-comments

Usage

In a single component


<template>
    <EasyComments
    :attrNameConfig=attrNameConfig
    :pluginConfig="pluginConfig"
    :apiConfig="apiConfig"
    >
    </EasyComments>
</template>

<script>

import EasyComments from '@kengo98/EasyComments.vue';

export default {
  name: 'App',
  components: {
    EasyComments
  },
  data(){
    return{
      attrNameConfig: {
          id: "id",
          text:"text", 
          userName: "userName",
          userPicture: "userPicture",
          dateCreated: "createdAt",
          userId: "userId",
          commentId: "commentId"
        },
        pluginConfig: {
            useAPI: true
        },
        apiConfig:{
            baseURL: "https://my-web-page/api/v1",
            endpoint: "/comments",
            headers: {
                'Content-Type': 'application/json'
            }
        },
    }
  }
}
</script>

DANGER

The following parameters are required, otherwise you will get an error
- pluginConfig
- apiConfig
- attrNameConfig

Parameters (Props)

The component has the following parameters available:

PropsDescriptionType
:attrNameConfigName of the attributes from the APIObject
:pluginConfigComponent configurationObject
:apiConfigData of the api from where the messages are retrievedObject
:textConfigConfiguration of the texts displayed in the componentObject
:currentUserIdIf you want to use delete and update features, if this attributes == comments.userIdNumber

:attrNameConfig

KeyTypeDescription
idStringid field name
textStringtext field name
userIdStringuser id field name
userNameStringuser name field name
userPictureStringuser image field name
dataCreatedStringcomment created date field name
commentIdStringcomment id field name

:pluginConfig

KeyTypeDescription
useAPIBooleanTrue: use api options to send data to API
customDeleteConfirmBooleanTrue: handle confirmationwith custom method
noUserImageStringpath to no user image when comments does not have userPicture

WARNING

useApi required to be , false for upcoming features

:apiConfig

KeyTypeDescription
baseURLStringAPI baseURL example: "https://my-web/api/v1"
endpointStringAPI endpoint example: "/comments"
headersStringrequired headers
customDataToSendArrayby default it only send text as defined attrNameConfig
responseSetupObject{onGet: Array, onPost: Array}
developmentModeBooleanset True to show sending data and responses from server

responseSetup

Example: if response from server when retrieve data with GET is:

  {
    message: "this is a response from server"
    comment: {
        id: 1   
        text: "this is a new comment"
        userId: 10
        userName: "myUserName"
        profilePicture: "https://example.com/image.jpg" 
        ...
    }
  }        

set apiConfig:

<script>
  setup(){
    return{
      apiConfig{
        useApi: true,
        reponseSetup: { onGet: ["comment"] }
      }
    }
  }
</script>
            

Another example:

  {
    message: "this is a response from server"
    data: {
      comments: {
        {
          id: 1   
          text: "this is a new comment"
          userId: 10
          userName: "myUserName"
          profilePicture: "https://example.com/image.jpg" 
          ...
        }
      }
    }
  }

set apiConfig:

<script>
  setup(){
    return{
      apiConfig{
        useApi: true,
        reponseSetup: { onGet: ["data","comment"] }
      }
    }
  }
</script>
            

To send the data to the server is the same way

:textConfig

This changes the words displayed in the component

KeyTypeDefault
replyStringReply
commentCountStringCOMMENT
commentCountManyStringCOMMENTS
newCommentStringNEW COMMENT
createButtonTextStringComment
updateButtonTextStringUpdate
responseButtonTextStringReply
CancelButtonTextStringCancel
updateStringUpdate
deleteStringDelete
updatingTextStringUPDATING
respondingTextStringRESPONDING:
createButtonTextStringCOMMENT

upcoming features

  • Use component without requiring API feature
Last Updated:
Contributors: Kengo Nakamura