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

Detailed tutorial on installing centos8 on VMware

CentOS official website address https://www.cento...

Implementation example of Docker rocketmq deployment

Table of contents Preparation Deployment process ...

How to Dockerize a Python Django Application

Docker is an open source project that provides an...

CSS to achieve Tik Tok subscription button animation effect

I was watching Tik Tok some time ago and thought ...

Thoughts on truncation of multi-line text with a "show more" button

I just happened to encounter this small requireme...

Detailed explanation of react setState

Table of contents Is setState synchronous or asyn...

Simple steps to encapsulate components in Vue projects

Table of contents Preface How to encapsulate a To...

How to deploy HTTPS for free on Tencent Cloud

Recently, when I was writing a WeChat applet, the...

The difference between absolute path and relative path in web page creation

1. Absolute path First of all, on the local compu...

Cross-domain issues in front-end and back-end separation of Vue+SpringBoot

In the front-end and back-end separation developm...

Example code of vue icon selector

Source: http://www.ruoyi.vip/ import Vue from ...

Summary of the most commonly used knowledge points about ES6 new features

Table of contents 1. Keywords 2. Deconstruction 3...

Detailed explanation of data types in JavaScript basics

Table of contents 1. Data Type 1.1 Why do we need...