vue 如何实现checkbox单选功能,不用radio的情形下

时间:2024-05-19 17:02:59

效果图

vue 如何实现checkbox单选功能,不用radio的情形下 

<el-table :data="gridData" :show-header="showHeader">
      <el-table-column width="200">
        <template slot-scope="scope">
          <el-checkbox-group v-model="scope.row.radioValue">
            <el-checkbox  false-label='null' :true-label="item.id" v-for="item in scope.row.radioList">{{item.name}}</el-checkbox>
          </el-checkbox-group>
        </template>
      </el-table-column>
      <el-table-column width="100" label="Action">
        <template slot-scope="scope">
          <el-button type="text" icon="ev-icon el-icon-arrow-up" title="up" class="ev-button-default-icon" slot="reference" @click="upOrder(scope.row,scope.$index)"></el-button>
          <el-button type="text" icon="ev-icon el-icon-arrow-down" title="down" class="ev-button-default-icon" slot="reference" @click="downOrder(scope.row,scope.$index)"></el-button>
        </template>
      </el-table-column>
    </el-table>
data() {
      return {
        showHeader:false,
        gridData: [
          {name:'LastModified',index:0,radioList:[{id:'ASC',name:'LastModified ASC'},{id:'DESC',name:'LastModified DESC'}]},
          {name:'LastActive',index:1,radioList:[{id:'ASC',name:'LastActive ASC'},{id:'DESC',name:'LastActive DESC'}]},
          {name:'Created',index:2,radioList:[{id:'ASC',name:'Created ASC'},{id:'DESC',name:'Created DESC'}]},
          {name:'Name',index:3,radioList:[{id:'ASC',name:'Name ASC'},{id:'DESC',name:'Name DESC'}]},
          {name:'Price',index:4,radioList:[{id:'ASC',name:'Price ASC'},{id:'DESC',name:'Price DESC'}]},
          {name:'Landlord',index:5,radioList:[{id:'ASC',name:'Landlord ASC'},{id:'DESC',name:'Landlord DESC'}]},
          {name:'Agent',index:6,radioList:[{id:'ASC',name:'Agent ASC'},{id:'DESC',name:'Agent DESC'}]},
          {name:'Status',index:7,radioList:[{id:'ASC',name:'Status ASC'},{id:'DESC',name:'Status DESC'}]},
        ],
      };
    },

核心代码:

<el-checkbox-group v-model="scope.row.radioValue">
            <el-checkbox  false-label='null' :true-label="item.id" v-for="item in scope.row.radioList">{{item.name}}</el-checkbox>
          </el-checkbox-group>