最近公司項目採用vue,實行先後端分離開發,採用element-ui框架,對於項目中遇到的問題進行記錄,便於往後查詢。css
vue+elementui怎樣點擊table中的單元格觸發事件?
官方文檔是採用的cell-click方式。實際項目中須要在不一樣的td上觸發不一樣事件,故採用能夠使用template-scope方式實現。以下圖所示 vue
element-ui中table帶了checkbox,獲取選中數據的話,按照文檔,須要先在table中綁定一個函數,假設以下element-ui
<el-table ref="jcqtTable" v-loading="loading" :data="jcqtTableCon" tooltip-effect="dark" stripe style="width: 100%" @select="handleSelect">
複製代碼
函數名稱是handleSelect,而後methods中定義這個方法後端
handleSelect(val) {
this.multipleSelection = val;
console.log("選中數據"+val);
let jcId = [];
this.multipleSelection.map((item) => {
jcId.push(item.id)
});
console.log("選中數據id:"+jcId);
return jcId;
}
複製代碼
<ul class="leftNavUl">
<li class="activeLi">
<router-link to='/pzgl/serviceManage' active-class="routerActive">
<span class="service"></span>
服務管理
</router-link>
</li>
<li>
<router-link to='/pzgl/hostManage' active-class="routerActive">
<span class="cloudhost"></span>
主機管理
</router-link>
</li>
<li>
<router-link to='/pzgl/passwordManage' active-class="routerActive">
<span class="passwordIcon"></span>
密碼維護
</router-link>
</li>
</ul>
複製代碼
這是左側紅框的路由bash
{
path: '/pzgl',
name: 'pzgl',
redirect: '/pzgl/serviceManage',
component: pzgl,
children: [{
path: 'serviceManage',
component: serviceManage
}, {
path: 'hostManage',
component: hostManage
}, {
path: 'passwordManage',
component: passwordManage
}]
}
複製代碼
.leftNavUl li a.routerActive{
background: #409eff;
color: #ffffff;
.service{
background: url('../assets/images/service_active.png') no-repeat;
}
.cloudhost{
background: url('../assets/images/cloudhost_active.png') no-repeat;
}
.passwordIcon{
background: url('../assets/images/password_active.png') no-repeat center;
}
}
複製代碼
css代碼大體就是這樣,設定好一個激活狀態的css類便可。框架