在table中使用el-checkbox单击事件会触发两次

313 阅读1分钟
 <div>
        <el-table>
         <el-table-column prop="status" label="启用" width="80px">
            <template slot-scope="{row}">
              <div @click.stop="e=>handleClick(e,row)">
                <el-checkbox v-model="row.status"/>
              </div>
            </template>
          </el-table-column>
       </table>
</div>        
  • 原因
    • 单击事件会触发两次,一次在label标签上,一次在input标签上
  • 解决方案
    • 禁用span/input中 一次单击事件的触发即可
      • if (e.target.tagName !== 'INPUT') return
      • if (e.target.tagName !== 'SPAN') return
if (e.target.tagName !== 'INPUT') return
// or
if (e.target.tagName !== 'SPAN') return