可编辑原生表格

该代码示例展示了如何使用Vue.js创建一个可编辑的表格,表格样式包括边框、单元格宽度和背景色等。通过组件实现编辑模式的切换,当editable为true时,表格单元格内的文本将变为可编辑的,反之则显示固定文本。表格数据绑定在formData对象上,包含各种收水和罐存信息。
摘要由CSDN通过智能技术生成

效果图:

 

<table></table> :
  style="tborder-color:#ccc;"           //边框颜色
  style="tborder-collapse:collapse;"    //表示边框合并在一起
  style="tborder-collapse:separate;"    //表示边框之间的间距
  style="tborder-spacing: px;"          //边框之间间距的大小
  style="table-layout: fixed;"          //单元格宽度固定防止被input变形
  border="1"                            //定义边框像素大小
  cellpadding="0"                       //边框与其内容的间隙大小
  cellspacing="0"                       //边框与边框之间的间隙大小
<tr></tr>:
  style="line-height: 40px"//行高度
<th></th>:
  colspan="1"//列数
  rowspan="2"//行数
  style=" width:6% ;"//列宽度
  style="background-color:#fafafa;"//单元格背景颜色
<span></span>:
  style="font-size: 18px;"  //span内字体大小

代码部分: 

<el-switch v-model="editable" active-text="解锁" inactive-text="锁定" style="margin:10px 0 0 0"></el-switch>
<table style=" padding-left : 20px ;padding-right: 20px;width: 100%; border-color: #ccc; border-collapse: collapse;table-layout: fixed;"
             border="1" cellspacing="0" cellpadding="0"   :data="formData" >
        <tr style="line-height: 40px">
          <th colspan="1" style=" width:6% ;background-color:#fafafa;"></th>
          <th colspan="1" style=" width:6% ;background-color:#fafafa;"></th>
          <th colspan="6" style=" width:66% ;background-color:#fafafa;">收水</th>
          <th colspan="2" rowspan="2" style=" width:22% ;background-color:#fafafa;">西林水</th>
        </tr>
        <tr  style="line-height: 40px">
          <th colspan="1" style=" background-color:#fafafa;"></th>
          <th colspan="1" style=" background-color:#fafafa;"></th>
          <th colspan="2" style=" background-color:#fafafa;">站内量</th>
          <th colspan="2" style=" background-color:#fafafa;">交接量</th>
          <th colspan="2" style=" background-color:#fafafa;">对比盈亏</th>
        </tr>
        <tr  style="line-height: 40px">
          <th colspan="1" style=" background-color:#fafafa;"></th>
          <th colspan="1" style=" background-color:#fafafa;"></th>
          <th colspan="1" style=" background-color:#fafafa;">日计</th>
          <th colspan="1" style=" background-color:#fafafa;">月累</th>
          <th colspan="1" style=" background-color:#fafafa;">日计</th>
          <th colspan="1" style=" background-color:#fafafa;">月累</th>
          <th colspan="1" style=" background-color:#fafafa;">日计</th>
          <th colspan="1" style=" background-color:#fafafa;">月累</th>
          <th colspan="1" style=" background-color:#fafafa;">日计</th>
          <th colspan="1" style=" background-color:#fafafa;">月累</th>
        </tr>
        <!--        方差行-->
        <tr  style="line-height: 40px">
          <th colspan="1" rowspan="2" style=" background-color:#fafafa;">西林线</th>
          <th colspan="1" style=" background-color:#fafafa;">方差</th>
          <th colspan="1" style=" background-color:#fafafa;">
            <span v-if="editable == false">{{formData.orgName}}</span>
            <el-input  v-else style="width: 100%" v-model="formData.orgName"></el-input>
          </th>
          <th colspan="1" style=" background-color:#fafafa;">
            <span>{{formData.orgName}}</span>
          </th>
          <th colspan="1" style=" background-color:#fafafa;">
            <span v-if="editable == false">{{formData.orgName}}</span>
            <el-input  v-else style="width: 100%" v-model="formData.orgName"></el-input>
          </th>
          <th colspan="1" style=" background-color:#fafafa;">
            <span>{{formData.orgName}}</span>
          </th>
          <th colspan="1" style=" background-color:#fafafa;">
            <span>{{formData.orgName}}</span>
          </th>
          <th colspan="1" style=" background-color:#fafafa;">
            <span>{{formData.orgName}}</span>
          </th>
          <th colspan="1" style=" background-color:#fafafa;">
            <span>{{formData.orgName}}</span>
          </th>
          <th colspan="1" style=" background-color:#fafafa;">
            <span>{{formData.orgName}}</span>
          </th>
        </tr>
        <tr  style="line-height: 40px">
          <th colspan="1" style=" background-color:#fafafa;">密度</th>
          <th colspan="1" style=" background-color:#fafafa;"></th>
          <th colspan="1" style=" background-color:#fafafa;"></th>
          <th colspan="1" style=" background-color:#fafafa;"></th>
          <th colspan="1" style=" background-color:#fafafa;"></th>
          <th colspan="1" style=" background-color:#fafafa;"></th>
          <th colspan="1" style=" background-color:#fafafa;"></th>
          <th colspan="1" style=" background-color:#fafafa;"></th>
          <th colspan="1" style=" background-color:#fafafa;"></th>
        </tr>
        <!--        -->
        <tr  style="line-height: 40px">
          <th colspan="1" rowspan="6" style=" background-color:#fafafa;">罐存情况</th>
          <th colspan="1" style=" background-color:#fafafa;">罐号</th>
          <th colspan="1" style=" background-color:#fafafa;">1#</th>
          <th colspan="1" style=" background-color:#fafafa;">2#</th>
          <th colspan="1" style=" background-color:#fafafa;">3#</th>
          <th colspan="1" style=" background-color:#fafafa;">4#</th>
          <th colspan="1" rowspan="2" style=" background-color:#fafafa;">水库存</th>
          <th colspan="3" rowspan="2" style=" background-color:#fafafa;">计划执行情况</th>
        </tr>
        <tr  style="line-height: 40px">
          <th colspan="1" style=" background-color:#fafafa;">罐位</th>
          <th colspan="1" style=" background-color:#fafafa;">
            <span v-if="editable == false">{{formData.orgName}}</span>
            <el-input  v-else style="width: 100%" v-model="formData.orgName"></el-input>
          </th>
          <th colspan="1" style=" background-color:#fafafa;">
            <span v-if="editable == false">{{formData.orgName}}</span>
            <el-input  v-else style="width: 100%" v-model="formData.orgName"></el-input>
          </th>
          <th colspan="1" style=" background-color:#fafafa;">
            <span v-if="editable == false">{{formData.orgName}}</span>
            <el-input  v-else style="width: 100%" v-model="formData.orgName"></el-input>
          </th>
          <th colspan="1" style=" background-color:#fafafa;">
            <span v-if="editable == false">{{formData.orgName}}</span>
            <el-input  v-else style="width: 100%" v-model="formData.orgName"></el-input>
          </th>
        </tr>
        <tr  style="line-height: 40px">
          <th colspan="1" style=" background-color:#fafafa;">混水</th>
          <th colspan="1" style=" background-color:#fafafa;">
            <span v-if="editable == false">{{formData.orgName}}</span>
            <el-input  v-else style="width: 100%" v-model="formData.orgName"></el-input>
          </th>
          <th colspan="1" style=" background-color:#fafafa;">
            <span v-if="editable == false">{{formData.orgName}}</span>
            <el-input  v-else style="width: 100%" v-model="formData.orgName"></el-input>
          </th>
          <th colspan="1" style=" background-color:#fafafa;">
            <span v-if="editable == false">{{formData.orgName}}</span>
            <el-input  v-else style="width: 100%" v-model="formData.orgName"></el-input>
          </th>
          <th colspan="1" style=" background-color:#fafafa;">
            <span v-if="editable == false">{{formData.orgName}}</span>
            <el-input  v-else style="width: 100%" v-model="formData.orgName"></el-input>
          </th>
          <th colspan="1" style=" background-color:#fafafa;"></th>
          <th colspan="1" style=" background-color:#fafafa;"></th>
          <th colspan="1" style=" background-color:#fafafa;">月计划</th>
          <th colspan="1" style=" background-color:#fafafa;">已完成</th>
        </tr>
        <tr  style="line-height: 40px">
          <th colspan="1" rowspan="3" style=" background-color:#fafafa;">运销记事</th>
          <th colspan="9" rowspan="1" style=" background-color:#fafafa;">今日收水方差亏{{''}}m³,密度盈{{''}}kg/m³,含水盈{{''}}%</th>
        </tr>
        <tr  style="line-height: 40px">
          <th colspan="9" rowspan="1" style=" background-color:#fafafa;padding-left: 20px" align="left">
            <el-col :span="8">
              收进口水泵运行时长:
              <span v-if="editable == false">{{formData.orgName}},</span>
              <el-input  v-else style="width: 200px" v-model="formData.orgName"></el-input>
            </el-col>
            <el-col :span="8">
              临家口泵运行时长:
              <span v-if="editable == false">{{formData.orgName}},</span>
              <el-input  v-else style="width:200px" v-model="formData.orgName"></el-input>
            </el-col>
          </th>
        </tr>
        <tr  style="height: 120px">
          <th colspan="9"rowspan="1" style=" background-color:#fafafa;" >
            <span v-if="editable == false">{{formData.orgName}}</span>
            <el-input type="textarea" :rows="5"
                      v-else style="width: 100%;height: 100%" v-model="formData.orgName">
            </el-input>
          </th>
        </tr>
      </table>
data(){
    return{
      formData:{
        orgName:'',
        },
      editable:false,
    }
  },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值