iview table中按鈕根據條件設置disabled


一、效果展示

 

 

 

 

 

 說明:當表格中存在未退款狀態的記錄,退款按鈕可用,當不存在未退款狀態的記錄,退款按鈕不可用

二、實現代碼

方法一:

disabled后直接跟true或者false的條件

 {
          title: '支付方式',
          key: 'paytype',
          // width: 250,
          align: 'center',
          render: (h, params) => {
            return h('div', this.getPayType(params.row.paytype));
          },
        },
        {
          title: '訂單狀態',
          key: 'orderstate',
          // width: 250,
          align: 'center',
          render: (h, params) => {
            return h('div', this.getOrderState(params.row.orderstate));
          },
        },
        {
          title: '操作',
          key: 'id',
          // width: 100,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h('Button', {
                props: {
                  type: 'primary',
                  size: 'small',
                  disabled: (params.row.canreturnprice === '0.00'),
                },
                on: {
                  click: () => {
                    this.$parent.addRemarks(params.row);
                  },
                },
              }, '退款'),
            ]);
          },
        },

方法二:

disabled后跟方法名,該方法返回true或者false

{
          title: '支付方式',
          key: 'paytype',
          // width: 250,
          align: 'center',
          render: (h, params) => {
            return h('div', this.getPayType(params.row.paytype));
          },
        },
        {
          title: '訂單狀態',
          key: 'orderstate',
          // width: 250,
          align: 'center',
          render: (h, params) => {
            return h('div', this.getOrderState(params.row.orderstate));
          },
        },
        {
          title: '操作',
          key: 'id',
          // width: 100,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h('Button', {
                props: {
                  type: 'primary',
                  size: 'small',
                  disabled: this.disabled(),
                },
                on: {
                  click: () => {
                    this.$parent.addRemarks(params.row);
                  },
                },
              }, '退款'),
            ]);
          },
        },
disabled() {
      let result = true;
      for (let i = 0; i < this.cardCancelInfo.length; i++) {
        console.log(this.cardCancelInfo[i]);
        if (this.cardCancelInfo[i].canreturnprice === '0.00') {
          result = true;
        } else {
          result = false;
        }
      }
      console.log(result);
      return result;
    },

三、需要注意的地方

 disabled: (params.row.canreturnprice === '0.00'),

條件一定為true或者false

 

 

 整形用

 disabled: (params.row.canreturnprice === 0.00),

字符串用

 disabled: (params.row.canreturnprice === '0.00'),

因為這個類型的問題,改了無數遍,試了無數的方法,就是覺得自己寫的對,就是實現不了,真是要哭了o(╥﹏╥)o

最后靈光一現,把條件的結果輸出出來,因為刪除是動態的,因此使用方法二,在watch中監聽disabled的方法,然后才知道在哪里入的坑,建議大家一定要看准類型,不要入坑啊๑乛◡乛๑卡在了奇怪的地方


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM