Click the toggle button in Vue to enable the button and then disable it

Click the toggle button in Vue to enable the button and then disable it

The implementation method is divided into three steps:

  1. Set two buttons in the template and control them through v-if and v-show;
  2. Set the default value of the button in data;
  3. Methods control the switching effect of clicking buttons.
<template>
  <el-table
    :data="tableData"
    border
    style="width: 100%">
    <el-table-column
      fixed
      prop="date"
      label="Date"
      width="200">
    </el-table-column>
     <el-table-column
      prop="state"
      label="Status"
      width="150">
    </el-table-column>
    <el-table-column
      prop="name"
      label="Name"
      width="120">
      <template slot-scope="scope">
            <el-input placeholder="Please enter content" v-show="scope.row.show" v-model="scope.row.name">
            </el-input>
            <span v-show="!scope.row.show">{{scope.row.name}}
            </span>
        </template>
    </el-table-column>
    <el-table-column
      prop="province"
      label="Province"
      width="120">
    </el-table-column>
    <el-table-column
      prop="city"
      label="Urban area"
      width="120">
    </el-table-column>
    <el-table-column
      prop="address"
      label="Address"
      width="300"
       :show-overflow-tooltip="true" >
    </el-table-column>
    <el-table-column
      prop="zip"
      label="zip code"
      width="120">
    </el-table-column>
    <el-table-column
      fixed="right"
      label="operation"
      width="300">
      <template slot-scope="scope">
        <el-button @click="handleClick(scope.row)" type="text" size="small">View</el-button>
        <el-button @click="scope.row.show =true" type="text" size="small">Edit</el-button>
        <el-button @click="scope.row.show =false" type="text" size="small">Save</el-button>
        <el-button @click="changeStatus" type="text" size="small" v-if="btnStatus == 0">Enable</el-button>
        <el-button @click="changeStatus" type="text" size="small" v-show="btnStatus == 1">Disable</el-button>

      </template>

    </el-table-column>
  </el-table>
</template>

<script>
  export default {
    methods: {
      handleClick(row) {
        console.log(row);
      },
      changeStatus(){
                this.btnStatus = this.btnStatus === 0 ? 1 : 0;
            }
    },

    data() {
      return {
          btnStatus: 0,
        tableData: [{
          date: '2016-05-02',

          name: 'Wang Xiaohu Wang Xiaohu Wang Xiaohu Wang Xiaohu Wang Xiaohu Wang Xiaohu Wang Xiaohu Wang Xiaohu Wang Xiaohu Wang Xiaohu Wang Xiaohu Wang Xiaohu Wang Xiaohu Wang Xiaohu Wang Xiaohu Wang Xiaohu Wang Xiaohu',
          province: 'Shanghai',
          city: 'Putuo District',
          address: 'No. 1518, Jinshajiang Road, Putuo District, Shanghai No. 1518, Jinshajiang Road, Putuo District, Shanghai',
          zip: 200333,
          show:true
        }, {
          date: '2016-05-04',

          name: 'Wang Xiaohu',
          province: 'Shanghai',
          city: 'Putuo District',
          address: 'No. 1517, Jinshajiang Road, Putuo District, Shanghai',
          zip: 200333,
          show:true
        }]
      }
    }
}
</script>

In addition, please note that the default value of the button should be placed under data, as shown in Figure 1.

It cannot be placed in a table, otherwise the button will not be displayed and an error will be reported. Figure 2: Property or method "btnStatus" is not defined on the instance but referenced during render.

The reason for this error is: "btnStatus" is used in the template or in the method, but it is not defined in the data.

This is the end of this article about the button becoming disabled after the click toggle button function in vue is enabled. For more relevant vue click toggle button content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue $attrs & inheritAttr to achieve button disabled effect case
  • Vue implements the function of prohibiting the selection of page content, only the input box and text field are optional
  • Detailed explanation of three ways to solve the label style in v-html elements in vue
  • How to disable the button tag style and function in Vue

<<:  Detailed explanation of mysql backup and recovery

>>:  Idea deployment tomcat service implementation process diagram

Recommend

How to implement line breaks in textarea text input area

If you want to wrap the text in the textarea input...

Vue implements chat interface

This article example shares the specific code of ...

MySQL 5.7.18 free installation version window configuration method

This is my first blog. It’s about when I started ...

How to connect to a remote docker server with a certificate

Table of contents 1. Use scripts to encrypt TLS f...

HTML table tag tutorial (34): row span attribute ROWSPAN

In a complex table structure, some cells span mul...

Tutorial on Installing Nginx-RTMP Streaming Server on Ubuntu 14

1. RTMP RTMP streaming protocol is a real-time au...

JS Easy to understand Function and Constructor

Table of contents 1. Overview 1.1 Creating a func...

Analysis of MySQL cumulative aggregation principle and usage examples

This article uses examples to illustrate the prin...

Detailed explanation of how to use the mysql backup script mysqldump

This article shares the MySQL backup script for y...

The difference between MySQL user management and PostgreSQL user management

1. MySQL User Management [Example 1.1] Log in to ...

Vue Beginner's Guide: Creating the First Vue-cli Scaffolding Program

1. Vue--The first vue-cli program The development...

Detailed analysis of mysql MDL metadata lock

Preface: When you execute a SQL statement in MySQ...

Why does using limit in MySQL affect performance?

First, let me explain the version of MySQL: mysql...