vue中使用iview表格元件如何為其某一項新增click事件, 為"操作","詳情"或者具體某一列新增連結操作
阿新 • • 發佈:2019-01-28
1.為"操作"列的每一項新增點選事件
通過給 columns 資料的項,設定一個函式 render,可以自定義渲染當前列,包括渲染自定義元件,它基於 Vue 的 Render 函式。render 函式傳入兩個引數,第一個是 h,第二個是物件,包含 row、column 和 index,分別指當前單元格資料,當前列資料,當前是第幾行。(檢視官網案例:https://www.iviewui.com/components/table)
2.為"詳情"列新增擴充套件引數項
<script> import expandRow from './expandRow.vue' export default { components: { expandRow }, data () { return { columns: [ { type: 'expand', title: '詳情', align: 'center', width: 60, render: (h, params) => { return h(expandRow, { props: { row: params.row } }) } }, { title: 'ID', key: 'id', align: 'center' }, { title: '專案名稱', key: 'projectname', align: 'center' } ] } } } </script>
3.table表格中某一列資料設定點選事件 (點選"訪問次數"彈出"訪問詳情列表" 或者為某一列資料新增連結)
render: (h, params) => {
let url = 'http://www.cainiao/projectView.php?pid=' + params.row.greenid
return h('a', {
attrs: {
href: url,
target: '_black'
}
}, params.row.greenid)
}
<script> export default { data () { return { columns: [ { title: '專案名稱', key: 'projectname', align: 'center' }, { title: '綠皮ID', key: 'greenid', align: 'center', render: (h, params) => { let url = 'http://www.cainiao/projectView.php?pid=' + params.row.greenid return h('a', { attrs: { href: url, target: '_black' } }, params.row.greenid) } }, { title: '訪問次數', key: 'pv', align: 'center', render: (h, params) => { return h('div', [ h('a', { props: { type: 'primary', size: 'small' }, style: { marginRight: '5px' }, on: { click: () => { this.show(params.row) } } }, params.row.pv) ]) } } ], } } } </script>