vue-table implements adding and deleting

vue-table implements adding and deleting

This article example shares the specific code for vue-table to add and delete for your reference. The specific content is as follows

1. Code

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>vue-table example</title>
    <style>
        .table_box {
            height: auto;
            width: 90%;
            margin: 5% auto;
        }

        .table {
            border-collapse: collapse;
            width: 100%;
            height: auto;
        }

        h1 {
            text-align: center;
        }
    </style>
</head>
<body>
<div id="app">
    <div class="table_box">
        <h1>Table Exercises</h1>
        <input type="text" v-model="text"/>
        <button @click="add">Add</button>
        <table class="table" border="1">
            <thead>
            <tr>
                <th>Serial number</th>
                <th>Brand</th>
                <th>Time</th>
                <th>Operation</th>
            </tr>

            </thead>
            <tbody>
            <tr v-for="(v,k) in list" :key="k">
                <th>{{v.id}}</th>
                <th>{{v.name}}</th>
                <th>{{v.time}}</th>
                <th>
                    <a href="#" @click.prevent="del(k)">Delete</a>
                </th>
            </tr>
            </tbody>
        </table>
    </div>

</div>
</body>
</html>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>

    var vm = new Vue({
        el: '#app',
        data: {
            num: 1,
            list: [],
            text: '',

        },
        methods: {
            add: function () {
                this.list.unshift({
                    "id": this.num++,
                    "name": this.text,
                    "time": new Date().toLocaleString(),
                });
            },
            del: function (index) {
                if (confirm("Are you sure you want to delete the current row")) {
                    this.list.splice(index, 1);
                }

            },

        }
    });
</script>

2. Operation effect

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:
  • Antd-vue Table component adds Click event to click on a row of data tutorial
  • vuejs element table table add rows, modify, delete rows individually, delete rows in batches
  • The VUE table dynamically adds a column of data, and the newly added data cannot be edited (the data bound to v-model cannot be updated in real time)

<<:  Detailed explanation of four solutions for MySQL active-active synchronous replication

>>:  Detailed explanation of how to use awk in Linux

Recommend

How to draw a vertical line between two div tags in HTML

Recently, when I was drawing an interface, I enco...

503 service unavailable error solution explanation

1. When you open the web page, 503 service unavai...

Complete steps for deploying confluence with docker

Confluence is paid, but it can be cracked for use...

Detailed explanation of binary and varbinary data types in MySQL

Preface BINARY and VARBINARY are somewhat similar...

How to show or hide common icons on the desktop in Windows Server 2012

Windows Server 2012 and Windows Server 2008 diffe...

Summary of important mysql log files

Author: Ding Yi Source: https://chengxuzhixin.com...

jQuery achieves fade-in and fade-out effects

Before using jQuery to complete the fade-in and f...

MySQL 8.0.24 version installation and configuration method graphic tutorial

This article records the installation and configu...

CSS transparent border background-clip magic

This article mainly introduces the wonderful use ...

MySQL 8.0.12 decompression version installation tutorial personal test!

Mysql8.0.12 decompression version installation me...

Linux CentOS 6.5 Uninstall, tar and install MySQL tutorial

Uninstall the system-provided MySQL 1. Check whet...

How to optimize MySQL deduplication operation to the extreme

Table of contents 1. Clever use of indexes and va...

How to install and modify the initial password of mysql5.7.18

For Centos installation of MySQL, please refer to...

Tutorial on installing JDK Tomcat MySQL on Linux (remote access using Mac)

One environment Alibaba Cloud Server: CentOS 7.4 ...