vue+elementui實(shí)現(xiàn)點(diǎn)擊table中的單元格觸發(fā)事件--彈框
elementui中提供了點(diǎn)擊行處理事件
查看位置: elementui的table事件
elementui的table中怎樣點(diǎn)擊某個(gè)單元格觸發(fā)事件?
可以先看一下官網(wǎng)中table的自定義列模板代碼
<template>
<el-table
:data="tableData"
border
style="width: 100%">
<el-table-column
label="日期"
width="180">
<template scope="scope">
<el-icon name="time"></el-icon>
<span style="margin-left: 10px">{{ scope.row.date }}</span>
</template>
</el-table-column>
<el-table-column
label="姓名"
width="180">
<template scope="scope">
<el-popover trigger="hover" placement="top">
<p>姓名: {{ scope.row.name }}</p>
<p>住址: {{ scope.row.address }}</p>
<div slot="reference" class="name-wrapper">
<el-tag>{{ scope.row.name }}</el-tag>
</div>
</el-popover>
</template>
</el-table-column>
<el-table-column label="操作">
<template scope="scope">
<el-button
size="small"
@click="handleEdit(scope.$index, scope.row)">編輯</el-button>
<el-button
size="small"
type="danger"
@click="handleDelete(scope.$index, scope.row)">刪除</el-button>
</template>
</el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [{
date: '2016-05-02',
name: '王小虎',
address: '上海市普陀區(qū)金沙江路 1518 弄'
}, {
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀區(qū)金沙江路 1517 弄'
}, {
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀區(qū)金沙江路 1519 弄'
}, {
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀區(qū)金沙江路 1516 弄'
}]
}
},
methods: {
handleEdit(index, row) {
console.log(index, row);
},
handleDelete(index, row) {
console.log(index, row);
}
}
}
</script>
點(diǎn)擊單元格彈出框可以使用template-scope方式實(shí)現(xiàn)
父組件
<el-table
:data="tableData"
border
style="width: 100%">
<el-table-column
label="編號"
prop = "number"
width="180">
<template scope="scope">
<div style="color:red;text-decoration:underline;cursor:pointer;" @click="getMore(scope.row)">{{ scope.row.date }}</div>
</template>
</el-table-column>
<el-table-column
label="名稱"
prop = "name"
width="180">
<template scope="scope">
<div style="color:red;text-decoration:underline;cursor:pointer;" @click="getMore2(scope.row)">{{ scope.row.date }}</div>
</template>
</el-table-column>
</el-table>
<el-dialog :visible-sync="getA">
<my-component :rowaa=row></my-component>
</el-dialog>
<el-dialog :visible-sync="getB">
<my-component2 :rowaa=row></my-component2>
</el-dialog>
<script>
import myComponent from './mycomponent'
import myComponent2 form './mycomponent2'
export default {
data() {
return {
tableData : [
{"number" : 1,"name":"y"},
{"number" : 2,"name":"x"},
],
getA : false,
getB : false,
row : ''
}
},
components: {
'my-component' : myComponent,
'my-component2' : myComponent2
},
methods : {
getMore(row) {
this.getA = true
this.row = row
},
getMore2(row) {
this.getB = true
this.row = row
}
}
}
</script>
子組件 mycomponent
<div>{{formData}}</div>
<script>
export default {
props: ['rowaa'],
data() {
return {
formData:''
}
},
created() {
this.getData()
},
watch : {
'rowaa' : 'getData'
},
methods: {
getData() {
//從后臺獲取數(shù)據(jù)邏輯 model.CacheModel.get('api/' + this.rowaa + '.json')
//通過this.rowaa就可以獲取傳過來的值
this.formData = 333
}
}
}
</script>
問題解決
可以使用template+slot插值進(jìn)行管理
點(diǎn)擊找到當(dāng)前行的信息,然后再根據(jù)該信息在子組件中請求數(shù)據(jù)
也試過通過點(diǎn)擊行的事件,判斷在哪一個(gè)單元格然后處理事件,這樣也可以,但如果在表格中列存放的內(nèi)容發(fā)生變化又得重新調(diào)整
也試過dialog彈出框直接寫在當(dāng)前單元格的template中,就像官網(wǎng)中例子一樣,但是這樣會在點(diǎn)擊時(shí)觸發(fā)多次(次數(shù)與當(dāng)前頁展示的數(shù)量一致)
補(bǔ)充知識:element cell-click使用方法
我就廢話不多說了,大家還是直接看代碼吧~
<el-table width="100%" border :data="Datalist" @cell-click="handle" >
methods: {
handle(row,column,event,cell) {
console.log(row)
console.log(column)
console.log(event)
console.log(cell)
}
}
以上這篇vue+elementui實(shí)現(xiàn)點(diǎn)擊table中的單元格觸發(fā)事件--彈框就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- vue之elementUi的el-select同時(shí)獲取value和label的三種方式
- 解決vue elementUI 使用el-select 時(shí) change事件的觸發(fā)問題
- Vue中ElementUI結(jié)合transform使用時(shí)彈框定位不準(zhǔn)確問題解析
- vue3+ts+elementui-plus二次封裝彈框?qū)崙?zhàn)教程
- vue.js基于ElementUI封裝了CRUD的彈框組件
- vue+elementui 實(shí)現(xiàn)新增和修改共用一個(gè)彈框的完整代碼
- Vue中ElementUI結(jié)合transform使用時(shí)如何修復(fù)el-select彈框定位不準(zhǔn)確問題
相關(guān)文章
Vue 如何使用props、emit實(shí)現(xiàn)自定義雙向綁定的實(shí)現(xiàn)
這篇文章主要介紹了Vue 如何使用props、emit實(shí)現(xiàn)自定義雙向綁定的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06
vue 數(shù)據(jù)遍歷篩選 過濾 排序的應(yīng)用操作
這篇文章主要介紹了vue 數(shù)據(jù)遍歷篩選 過濾 排序的應(yīng)用操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11
Vue中使用vue2-perfect-scrollbar制作滾動條
這篇文章主要介紹了Vue中使用vue2-perfect-scrollbar滾動條,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06
vue vuex vue-rouert后臺項(xiàng)目——權(quán)限路由(適合初學(xué))
這篇文章主要介紹了vue vuex vue-rouert后臺項(xiàng)目——權(quán)限路由,通過本文可以很清除的捋清楚vue+vuex+vue-router的關(guān)系,本版本非常簡單,適合初學(xué)者,需要的朋友可以參考下2017-12-12
vue如何實(shí)現(xiàn)路由跳轉(zhuǎn)到外部鏈接界面
這篇文章主要介紹了vue如何實(shí)現(xiàn)路由跳轉(zhuǎn)到外部鏈接界面,具有很好的參考價(jià)值,希望對大家有所幫助。2022-10-10
vue.extend實(shí)現(xiàn)alert模態(tài)框彈窗組件
這篇文章主要為大家詳細(xì)介紹了vue.extend實(shí)現(xiàn)alert模態(tài)框彈窗組件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04
vue項(xiàng)目實(shí)現(xiàn)img的src動態(tài)賦值
這篇文章主要介紹了vue項(xiàng)目實(shí)現(xiàn)img的src動態(tài)賦值方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03
Vue路由組件的緩存keep-alive和include屬性的具體使用
:瀏覽器頁面在進(jìn)行切換時(shí),原有的路由組件會被銷毀,通過緩存可以保存被切換的路由組件,本文主要介紹了Vue路由組件的緩存keep-alive和include屬性的具體使用,感興趣的可以了解一下2023-11-11

