iview table editable

 

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="http://unpkg.com/iview/dist/styles/iview.css">
    <script type="text/javascript" src="http://vuejs.org/js/vue.min.js"></script>
    <script type="text/javascript" src="http://unpkg.com/iview/dist/iview.min.js"></script>
</head>
<body>
 
<div id="app">
    <i-table border :columns="columns2" :data="data3"></i-table>
</div>
 
<script>
    
    var app = new Vue({
        el: '#app',
        data () {
            return {
                    columns2: [
                        {
                            width: 60,
                            align: 'center',
                            render: (h, params) =>{
                                 Return H ( ' Checkbox ' , { 
                                    The props: { 
                                        value: the params .Row $ isEdit,. 
                                    }, 
                                    ON: { 
                                        ' ON-Change ' : function ( State ) { 
                                            the console.log ( State ); 
// not iview table from CheckBox own reconstruction with a click of the assignment
params .Row. $ isEdit = State } } }); } }, { title: 'Name', key: 'name' }, { title: 'Age', key: 'age', render: (h, params) => { if (params.row.$isEdit) { return h('input', { domProps: { value: params.row.age }, on: { input: function (event) { params.row.age = event.target.value } } }); } else { return h('div', params.row.age); } } }, { title: 'Address', key: 'address' }, { title: 'Action', key: 'action', render: (h, params) => { return h('Button', { props: { type: 'text', size: 'small' }, on: { click: () => { if (params.row.$isEdit) { this.handleSave(params.row) } else { this.handleEdit(params.row) } } } }, params.row.$isEdit ? '保存' : '编辑') } } ], DATA3: [ { name: ' ha ' , Age: 18 is , address: ' Shanghai ' , $ isEdit: to false }, { name: ' la ' , Age: 24 , address: ' Beijing ' , $ isEdit: to false } ] } }, methods: { // select_row(selection,index){ // console.log('select_row',selection,index) // this.$set(this.data3[index], '$isEdit', true) // }, handleEdit (row) { console.log('handleEdit',row); this.$set(row, '$isEdit', true) }, handleSave (row) { console.log('handleSave',row); this.$set(row, '$isEdit', false) } } }) </script> </body> </html>

 

Guess you like

Origin www.cnblogs.com/hzx-5/p/11587165.html