<el-table :data="tableData" style="width: 100%">
//---:data="用于存放請求數(shù)據(jù)回來的數(shù)組"
<el-table-column label="索引值" width="400">
<template slot-scope="scope">//--- 這里取到當(dāng)前單元格
<span>{{ scope.$index }}</span>//--- scope.$index就是索引
</template>
</el-table-column>
<el-table-column label="標(biāo)題" width="350">
<template slot-scope="scope">//--- 這里取到當(dāng)前單元格
<span>{{ scope.row.title }}</span>
//--- scope.row 直接取到該單元格對象,就是數(shù)組里的元素對象,即是tableData[scope.$index]
//---.title 是對象里面的title屬性的值
</template>
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">//--- 這里取到當(dāng)前單元格
<el-dropdown size="medium" split-button type="primary">
更多
<el-dropdown-menu slot="dropdown">
<el-dropdown-item @click.native.prevent="handleEdit(scope.$index, scope.row)">編輯</el-dropdown-item>
<el-dropdown-item @click.native.prevent="getUp(scope.$index, scope.row)">上升</el-dropdown-item>
<el-dropdown-item @click.native.prevent="getDown(scope.$index, scope.row)">下降</el-dropdown-item>
<el-dropdown-item @click.native.prevent="handleDelete(scope.$index, scope.row)">刪除</el-dropdown-item>
//---這里的點(diǎn)擊事件已經(jīng)不是在根元素上了,因?yàn)槎嗵琢藥讓咏Y(jié)構(gòu)。
//---這里的點(diǎn)擊事件如果沒有加上 .native 則點(diǎn)擊無效!
//---這里的點(diǎn)擊事件要加上 .native 表示監(jiān)聽組件根元素的原生事件。
//---這里的點(diǎn)擊事件不需要 .prevent 也可以實(shí)現(xiàn)相同效果
</el-dropdown-menu>
</el-dropdown>
</template>
</el-table-column>
</el-table>
<script>
data() {
return {
tableData: [{title:123,age:11},{title:456,age:18}]
//---為了效果先給值,一般情況下為空,其實(shí)際值是后臺(tái)接口請求回來的
}
},
methods:{
handleDelete(index, row) {
this.tableData.splice(index+1, 1);//---前端刪除index要+1 !!!!!!!
//---下面是后端數(shù)據(jù)刪除,可以不看
axios.post(config.newsDelete,//---后端數(shù)據(jù)刪除
{
id: row.id//---傳入被刪除的對象的id值
},
{
headers: {
Authorization: "Bearer " + sessionStorage.getItem("token")//---請求頭驗(yàn)證
}
}
)
.then(res => {
this.rendering()//---刪除了重新渲染
});
}
}
</script>
slot-scope="scope"
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 1.key key 的特殊屬性主要用在 Vue 的虛擬 DOM 算法,在新舊 nodes 對比時(shí)辨識(shí) VNodes...
- 1. 實(shí)例效果: 2. 實(shí)例運(yùn)用到的組件: 這里的實(shí)例 運(yùn)用 element 的 表格組件:el-table 下拉...
- 官方文檔 即插槽,插槽定義在子組件內(nèi),是組件的一塊HTML模板,可以在子組件內(nèi)設(shè)置默認(rèn)值,也可以在父組件內(nèi)定義插槽...
- 是金子總會(huì)發(fā)光 是銀子總會(huì)被發(fā)現(xiàn) 而你我如同石頭沒有被發(fā)現(xiàn)更不會(huì)發(fā)光。埋藏地下。丟在河邊。凡夫俗子咋能看破。殊不知...