vxe-table 可以編輯模式和只讀模式的引數是 editConfig.enabled 當需要編輯時就啟用,當不需要編輯時就關閉
官網:https://vxetable.cn/
<template>
<div>
<vxe-button status="primary" @click="toggleReadonly">切換</vxe-button>
<vxe-grid v-bind="gridOptions"></vxe-grid>
</div>
</template>
<script>
export default {
data () {
const sexEditRender = {
name: 'VxeSelect',
options: [
{ label: '女', value: 'Women' },
{ label: '男', value: 'Man' }
]
}
const gridOptions = {
border: true,
showOverflow: true,
editConfig: {
enabled: true,
trigger: 'click',
mode: 'row'
},
columns: [
{ type: 'seq', width: 70 },
{ field: 'name', title: '名稱', minWidth: 200, editRender: { name: 'VxeInput' } },
{ field: 'sex', title: '性別', width: 200, editRender: sexEditRender },
{ field: 'age', title: '年齡', minWidth: 200, editRender: { name: 'VxeNumberInput' } }
],
data: [
{ id: 10001, name: 'Test1', role: 'role2', sex: '', age: 24 },
{ id: 10002, name: 'Test2', role: 'role10', sex: 'Women', age: 24 },
{ id: 10003, name: 'Test3', role: 'role200', sex: 'Man', age: 24 }
]
}
return {
gridOptions,
sexEditRender
}
},
methods: {
toggleReadonly () {
this.gridOptions.editConfig.enabled = !this.gridOptions.editConfig.enabled
}
}
}
</script>
https://gitee.com/x-extends/vxe-table