Vue implements simple comment function

Vue implements simple comment function

This article shares the specific code of Vue to implement a simple comment function for your reference. The specific content is as follows

1. This is an example of my study. There are some deficiencies. I hope you can give me some advice. Thank you~

2. The effect of posting comments

The effect after clicking "Publish" (Click "Delete" after each comment to delete the entire comment~)

3. Complete code display (my HTML structure is messy, here I would like to remind you that the div without a defined class can be deleted. I added more divs for the convenience of writing styles)

I still want to remind you, don't forget to import vue.js, and remember to change the directory according to your storage location

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title></title>
  <script src="./vue.js"></script>
  <style type="text/css">
   *{
    margin: 0;padding: 0;
    box-sizing: border-box;
   }
   #app{
    width: 700px;
    height: 650px;
    margin: auto;
    border: 1px solid #ccc;
   }
   #app h1{
    width: 700px;
    font-weight: 400;
    line-height: 100px;
    padding-left: 20px;
    background-color: #cccccc;
    margin-bottom: 20px;
   }
   #app>div{
    padding: 0 20px;
   }
   #app>div>input{
    width: 200px;
    height: 30px;
    padding: 0 5px;
    margin: 5px 0;
   }
   #app>div>textarea{
    padding: 5px;
    margin-top: 5px;
   }
   .cont div{
    height: 50px;
    border: 1px solid #acacac;
    border-radius: 5px;
    padding: 0 10px;
   }
   .cont div span{
    padding: 0 5px;
    line-height: 50px;
   }
   .cont p{
    display: inline-block;
   }
   .cont div p:nth-of-type(1){
    color: #550000;
   }
   .cont div p:nth-of-type(2){
    color: #595959;
   }
   .cont .del{
    float: right;
    line-height: 50px;
    color: #003366;
    cursor: pointer;
   }
   .cont .del:hover{
    color: #550000;
   }
   .send{
    width: 80px;
    height: 30px;
    margin-top: 10px;
   }
   hr{
    border: 1px solid #bababa;
    margin: 15px 0;
   }
   h3{
    font-weight: 400;
    color: #333;
    margin-bottom: 10px;
   }
  </style>
 </head>
 <body>
  <div id="app">
   <h1>Welcome to the Tucao Hall</h1>
   <div>
    <label>Username:</label><br>
    <!-- .trim removes spaces in the content -->
    <!-- v-model binds the form's (uname) value -->
    <input type="text" placeholder="Username" v-model.trim="uname" /><br>
    <label>Comments:</label><br>
    <textarea rows="2" cols="23" placeholder="Tucao content" v-model.trim="tarea"></textarea><br>
    <!-- @click="",Set click event-->
    <button class="send" @click="sendCont()">Publish</button>
    <hr>
    <h3>Tucao reply:</h3>
    <!-- Traverse list data-->
    <div class="cont" v-for="val in list" :key="val.name">
     <div>
      <p>{{val.name}}</p><span>says:</span>
      <p>{{val.item}}</p>
      <p class="del" @click="delCont(val)">Delete</p>
     </div>
    </div>
   </div>
  </div>
  <script type="text/javascript">
   new Vue({
    el:"#app", //Specify template data:{
     list:[
      {"name":"beibei","item":"Mom, I want to eat baked sweet potatoes"},
      {"name":"dian","item":"eat,eat big chunks"},
     ],
     uname:"",
     Tarea:"",
    },
    methods:{
     // "Publish" button click event sendCont(){
      // Create a list var item = {name:this.uname,item:this.tarea};
      // Add item to the front of the list
      this.list.unshift(item);
      // User box, content box clear this.uname="";
      this.tarea="";
     },
     // Comment on the last "delete" event delCont(val){
      alert("Are you sure you want to delete?");
      // Find the index of val in list // The element traversed by value when the item/name value of value is equal to the item/name value of val var ind = this.list.findIndex(value=>value.item===val.item);
      // Delete the indth item in list this.list.splice(ind,1);
     }
    }
   })
  </script>
 </body>
</html>

4. That’s it. I wish you all a happy study. Goodbye.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Vue implements comment function
  • Vue implements article comments and reply lists
  • VUE+Java implements comment reply function
  • Vue component to realize comment area function
  • Vue development to realize comment list
  • Vue implements comment list
  • Vue implements comment list function
  • Implementation of Vuepress to build a static blog with comment function
  • Vue.js implements article comment and reply comment functions
  • Vue component implements comment function

<<:  Solution to docker suddenly not being accessible from the external network

>>:  HTML tag ID can be a variable

Recommend

MySQL SQL Optimization Tutorial: IN and RANGE Queries

First, let's talk about the in() query. It is...

JavaScript pre-analysis, object details

Table of contents 1. Pre-analysis 1. Variable pre...

Detailed tutorial on how to install mysql8.0 using Linux yum command

1. Do a good job of cleaning before installation ...

Getting Started: A brief introduction to HTML's basic tags and attributes

HTML is made up of tags and attributes, which are...

Two ways to remove the 30-second ad code from Youku video

I believe everyone has had this feeling: watching ...

Vue routing returns the operation method of restoring page status

Route parameters, route navigation guards: retain...

A brief discussion on using Vue to complete the mobile apk project

Table of contents Basic Configuration Entry file ...

JavaScript object-oriented implementation of magnifying glass case

This article shares the specific code of JavaScri...

Detailed steps to install MySQL 8.0.27 in Linux 7.6 binary

Table of contents 1. Environmental Preparation 1....

How to process local images dynamically loaded in Vue

Find the problem Today I encountered a problem of...

Using CSS3 to create header animation effects

Netease Kanyouxi official website (http://kanyoux...

Solution to the problem of large font size on iPhone devices in wap pages

If you don't want to use javascript control, t...

Summary of various methods for JS data type detection

Table of contents background What are the methods...

Vue implements book management case

This article example shares the specific code of ...