使用elementui中的表格组件,在表头里面加入输入框。绑定了值,但是输入框输入不进去值。

使用elementui中的el-table,在表头里面加入输入框,但是输入框输入不进去值

<el-table
        :data="records"
        highlight-current-row
        height="60px"
        style="min-height: 100%"
      >
        <el-table-column align="center">
          <template slot="header" slot-scope="scope">
            <p>商家</p>
            <el-input
              v-model="merchant"
              clearable
              size="small"
            ></el-input>
          </template>
          <template slot-scope="scope">
            <span>{{ scope.row.merchant}}</span>
          </template>
        </el-table-column>
</el-table>

因为用了eslint没有使用变量的话会报错,所以上面的代码<template slot="header" slot-scope="scope">会报scope定义了但是没有使用的错误,这时候如果把slot-scope="scope"删掉,确实就没有eslint报错问题了,但是就会出现里面的输入框输入不了值的问题,想输入值在template里面必须加slot-scope=“scope”

解决方法1:为了解决eslint报错,可以在报错的语句上面加上注释(<!-- eslint-disable-next-line -->),让eslint不再进行检验,正确的代码如下:

<el-table
        :data="records"
        highlight-current-row
        height="60px"
        style="min-height: 100%"
      >
        <el-table-column align="center">
        <!--在报错的行上加入下面的注释   -->
        <!-- eslint-disable-next-line -->
          <template slot="header" slot-scope="scope">
            <p>商家</p>
            <el-input
              v-model="merchant"
              clearable
              size="small"
            ></el-input>
          </template>
          <template slot-scope="scope">
            <span>{{ scope.row.merchant}}</span>
          </template>
        </el-table-column>
</el-table>

解决方法2:将slot="header"换成#header,就不用加后面的slot-scope="scope"了。

<el-table
        :data="records"
        highlight-current-row
        height="60px"
        style="min-height: 100%"
      >
        <el-table-column align="center">
          <template #header>
            <p>商家</p>
            <el-input
              v-model="merchant"
              clearable
              size="small"
            ></el-input>
          </template>
          <template slot-scope="scope">
            <span>{{ scope.row.merchant}}</span>
          </template>
        </el-table-column>
</el-table>
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值