Vue 中 @click.native.prevent; slot-scope="scope" (scope.$index, scope.row)
阿新 • • 發佈:2020-08-16
看別人部落格時看到了@click.native.prevent;和slot-scope="scope" (scope.$index, scope.row)於是就查了一下。
@click.native.prevent
1.給vue元件繫結事件時候,必須加上native ,否則會認為監聽的是來自Item元件自定義的事件,
2.prevent 是用來阻止預設的 ,相當於原生的event.preventDefault()
<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> </el-dropdown-menu>
slot-scope="scope" (scope.$index, scope.row)
slot-scope="scope" //取到當前單元格
scope.$index→拿到每一行的index
scope.$row→拿到每一行的資料