今天使用vue,以及element-ui這個框架時,發現業務需要在表格里加一個連接跳轉,當時立刻打開element的官網,進行查看http://element-cn.eleme.io/#/zh-CN/component/table是在<el-table>里進行添加事件的,而此時我進行嘗試后發現這個是每一個單元格都需要跳轉,不是我想要的針對某一列進行的點擊跳轉操作,於是各種技術貼開始搜索,最后發現一個網友的寫法很可行。
我把參考網站貼出來https://segmentfault.com/q/1010000012511902
<el-table-column prop="goods_count" label="活動兌換商品" align="center" width="150" > <template slot-scope="scope"> <el-button type="text" size="small" @click="handleGoods(scope.row)" v-if="scope.row.goods_count==0">管理活動商品</el-button> <el-button type="text" size="small" @click="handleGoods(scope.row)" v-else>{{scope.row.goods_count}}</el-button> </template> </el-table-column>
handleJoinGoods(row,id){ console.log(row.goods_count); }
其中<el-button>也可以換成別的你想要的標簽,都是沒有問題的。好了 這樣問題就解決啦!