這篇文章將為大家詳細(xì)講解有關(guān)VUE-Table中如何綁定Input通過(guò)render實(shí)現(xiàn)雙向綁定數(shù)據(jù),小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
效果
HTML的Table
<Card> <div ref="print" > <Table width="100%" height="500" size="small" :columns="columns7" :stripe="true" :data="data" border ></Table> </div> </Card>
JS代碼
<script> export default { data () { return { columns7: [ { title: '序號(hào)', type: 'index', width: 200 }, { title: '新批次', width: 350, key:'newLots' }, { title: '數(shù)量', key: 'numLots', width: 350, align: 'center', render: (h, params) => { var vm = this; return h('div', [ h('Input', { props: { //將單元格的值給Input value:params.row.numLots, }, on:{ 'on-change' (event) { //值改變時(shí) //將渲染后的值重新賦值給單元格值 params.row.numLots = event.target.value; vm.data[params.index] = params.row; } } },) ]); } }, { title: '操作', key: 'action', width: 350, align: 'center', render: (h, params) => { return h('div', [ h('Button', { props: { type: 'error', size: 'default' }, style: { marginRight: '5px' }, on: { click: () => { this.openDeleteDialog(params.index) } } }, '刪除') ]); } } ], data: [], } } } </script>
這樣就實(shí)現(xiàn)Input和Table單元格數(shù)據(jù)的雙向綁定,取值是直接循環(huán)單元格來(lái)取值。
雙向綁定數(shù)據(jù)的核心代碼:
on:{ 'on-change' (event) { //值改變時(shí) //將渲染后的值重新賦值給單元格值 params.row.numLots = event.target.value; vm.data[params.index] = params.row; } }
完成~
關(guān)于“VUE-Table中如何綁定Input通過(guò)render實(shí)現(xiàn)雙向綁定數(shù)據(jù)”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
網(wǎng)頁(yè)名稱:VUE-Table中如何綁定Input通過(guò)render實(shí)現(xiàn)雙向綁定數(shù)據(jù)-創(chuàng)新互聯(lián)
本文網(wǎng)址:http://www.sd-ha.com/article20/phhco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、靜態(tài)網(wǎng)站、微信小程序、品牌網(wǎng)站制作、網(wǎng)站改版、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容