vue中的slot-scope及scope.row用法
slot-scope及scope.row的用法
最近在寫后臺管理系統 在寫到修改的地方時 之前的思路是直接把當前對象傳過去 然后在進行修改
現在vue提供了scope 以及 scope.row 可以讓我們更方便的操作數據
slot-scope='scope'作用域插槽中定義一個對象(這里對象被定義為scope)來存儲插槽上綁定的數據的用法scope.row使用ElementUI表格模板渲染數據時使用
當前行數據的獲取也會用到插槽,scope相當于一行的數據, scope.row相當于當前行的數據對象
<el-table :data="userList" stripe style="width: 100%"> ? ? ? <el-table-column prop="username"label="姓名" width="180"></el-table-column> ? ? ? <el-table-column prop="email" label="郵箱" width="180"> </el-table-column> ? ? ? <el-table-column prop="mobile" label="電話"> </el-table-column> ? ? ? <el-table-column label="用戶狀態(tài)"> ? ? ? ? <template slot-scope="scope"> ? ? ? ? ? <el-switch v-model="scope.row.mg_state" @change="userstateChange(scope.row.id, scope.row.mg_state)"> ? ? ? ? ? </el-switch> ? ? ? ? </template> ? ? ? </el-table-column> ? ? ? <el-table-column prop="adress" label="操作"> </el-table-column> </el-table>
:data ==》“userList”
表格綁定了用于存儲數據的數組,里面每一個元素都是數據對象
slot-scope ==》“scope”
這是作用域插槽中定義一個對象(這里對象被定義為scope)來存儲插槽上綁定的數據的用法
當前行的數據對象 ==》 scope.row
在這里使用ElementUI表格模板渲染數據時,當前行數據的獲取也會用到插槽,scope相當于一行的數據, scope.row相當于當前行的數據對象
還是比較方便的~
vue項目中slot-scope="scope"報錯scope is defined but never used

報錯是由于eslint的檢測機制造成的
解決方法
在template上 加上 eslint-disable-next-line 注釋即可

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Vue實現動態(tài)創(chuàng)建和刪除數據的方法
下面小編就為大家分享一篇Vue實現動態(tài)創(chuàng)建和刪除數據的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03

