iView에서 편집 가능한 테이블을 구현하는 방법 소개(코드 포함)
Feb 20, 2019 pm 02:08 PM이 글은 iView에서 편집 가능한 테이블을 구현하는 방법(코드 포함)을 소개합니다. 필요한 친구들이 참고할 수 있기를 바랍니다.
Component
<i-table highlight-row ref="currentRowTable" :columns="columns" :data="tableData"></i-table>
구현 방법:
현재 편집해야 하는 열의 ID를 기록합니다. 기본값은 비어 있습니다.
편집해야 하는 열이 현재 편집해야 하는 열의 ID와 일치합니다. 편집되고 성공하면 열이 렌더링됩니다. 입력 레이블 구성 요소를 포함하고 입력 이벤트를 바인딩하려면
데이터 처리
export default { data () { return { currentId: '', currentScore: '', columns: [ { title: '名称', key: 'name', align: 'center' }, { title: '班级', align: 'center', render: (h, p) => { const { id, score } = p.row const inp = h('input', { style: { width: '30%', padding: '4px 2px', borderRadius: '4px', border: '1px solid #e9eaec', textAlign: 'center' }, attrs: { maxlength: 16 }, domProps: { value: score }, on: { input: (event) => { this.currentScore = event.target.value } } }) return this.currentId === p.row.id ? inp : h('span', score) } }, { title: '操作', align: 'center', render: (h, p) => { const { currentId } = this const { id } = p.row const btnEdit = h('i-button', { on: { click: () => { this.currentId = id } } }, '编辑') const btnSaveCancel = [ h('i-button', { on: { click: () => { this.handleSave(id) } } }, '保存'), h('i-button', { on: { click: () => { this.currentId = '' this.currentScore = '' } } }, '取消')] return currentId === id ? h('p', btnSaveCancel) : btnEdit } } ], tableData: [ { id: 1, name: 1, score: 1 }, { id: 2, name: 2, score: 2 }] } }, methods: { handleSave (id) { const {currentScore, tableData} = this this.tableData = tableData.map(v => { return v.id === id ? { ...v, score: currentScore } : v }) this.currentId = '' this.currentScore = '' } } }
참고: 헤드 태그에 iView가 도입된 경우 이 방법은 다음과 같습니다. 프로젝트에서 유효하지 않습니다. 컴파일을 통해 개발된 프로젝트는 가능합니다.
위 내용은 iView에서 편집 가능한 테이블을 구현하는 방법 소개(코드 포함)의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

인기 기사

인기 기사

뜨거운 기사 태그

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











WebSocket과 JavaScript를 사용하여 온라인 음성 인식 시스템을 구현하는 방법

WebSocket 및 JavaScript: 실시간 모니터링 시스템 구현을 위한 핵심 기술

WebSocket과 JavaScript를 사용하여 온라인 예약 시스템을 구현하는 방법

JavaScript 및 WebSocket을 사용하여 실시간 온라인 주문 시스템을 구현하는 방법

간단한 JavaScript 튜토리얼: HTTP 상태 코드를 얻는 방법

JavaScript와 WebSocket: 효율적인 실시간 일기예보 시스템 구축
