InputNumber 踩坑“
先给效果图:
html:
<!-- 列表 -->
<Col span="15">
<Table border size="small" ref="selection" :height="height" :columns="historyColumns" :data="historyData" @on-select-all="selectTable" @on-select-all-cancel="selectTable_Cancel" @on-select-cancel="item_Cancel" @on-select="row_Select" @on-selection-change="row_Select">
</Table>
<Row type="flex" style="margin-top:10px">
<Col span="2" style="margin-left: 1.5%;" v-show="selectData == true">
<span style="display:inline-block; height:32px; line-height:32px;">音量值:</span>
</Col>
<Col span="3" v-show="selectData == true">
<InputNumber type="number" v-model="volume" :min="0" :max="40"></InputNumber>
</Col>
<Col span="3">
<div style="position: fixed;right: 5%;" v-show="showSumit">
<Button size="large" style="padding: 10px 15px 10px 15px;" type="primary" @click="sumitData()">提交</Button>
</div>
</Col>
</Row>
</Col>
js:
return {
volume: null,
historyColumns: [
{type: 'selection',width:60,align: 'left'},
{title: '序号', type:'index', align:'center', width:70},
{title: '线路', key: 'lineName',width:80},
{title: '车站', key: 'stationName'},
{title: '分区', key: 'areaName'},
{title: '音量', key: 'volume',width:90,align:'center',type:'number',
render:(h,params)=>{
return h('div',[
h('InputNumber',{
props:{
min: 0,
max: 40,
value: this.volume !== null ? this.volume : params.row.volume,
},
style:{
height: "30px !important",
width: "95%",
},
on:{
'on-change':(event)=>{
// console.log("InputNumber:",event);
// params.row.volume = event;
this.historyData[params.index].volume = event;
}
}
})
])
}
},
}
尤其注意的是后台返回列表: this.historyData = res.data.result;
但是列表为啥不显示:音量值呢?
这里需要判断下,你这volume的值 是 定义的 this.volume 的值,还是 this.historyData[i].volume 的值。
三元表达式就可以解决了。
value: this.volume !== null ? this.volume : params.row.volume,