最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vue element table bind selected row - Stack Overflow

programmeradmin4浏览0评论

I need help with an element.eleme.io table inside a vue ponent. How do I bind a row in my table which is selected with a button to my Vue data object?

<el-form-item>
  <el-table
    v-model="userData.operation"
    :data="operations"
    border
    row-key="operationId"
    v-if="choosingOperation"
    size="small">
    <el-table-column
      prop="operationName"
      label="Einsatz-Name">
    </el-table-column>
    <el-table-column
      prop="operationAdress"
      label="Einsatz-Adresse">
    </el-table-column>
    <el-table-column
      prop="operationStaffType"
      label="Typ">
    </el-table-column>
    <el-table-column
      fixed="right"
      label="Optionen"
      width="120">
      <template slot-scope="scope">
        <el-button
          @click="userData.operation = operations[operationID]"
          type="text"
          size="small">
          Wählen
        </el-button>
      </template>
    </el-table-column>
  </el-table>
</el-form-item>

I want the chosen row (object operation: {operationName: '', operationStafftype: '', operationAdress: '', operationId: 0}) to be stored in my data-object as operation. my chosen approach in the example (use row-key) does not work.

export default {
  data () {
    return {
      userData: {
        operation: {},
        role: '',
        position: '',
        sender: '',
        identification: ''
      },

Thank you very much!

I need help with an element.eleme.io table inside a vue ponent. How do I bind a row in my table which is selected with a button to my Vue data object?

<el-form-item>
  <el-table
    v-model="userData.operation"
    :data="operations"
    border
    row-key="operationId"
    v-if="choosingOperation"
    size="small">
    <el-table-column
      prop="operationName"
      label="Einsatz-Name">
    </el-table-column>
    <el-table-column
      prop="operationAdress"
      label="Einsatz-Adresse">
    </el-table-column>
    <el-table-column
      prop="operationStaffType"
      label="Typ">
    </el-table-column>
    <el-table-column
      fixed="right"
      label="Optionen"
      width="120">
      <template slot-scope="scope">
        <el-button
          @click="userData.operation = operations[operationID]"
          type="text"
          size="small">
          Wählen
        </el-button>
      </template>
    </el-table-column>
  </el-table>
</el-form-item>

I want the chosen row (object operation: {operationName: '', operationStafftype: '', operationAdress: '', operationId: 0}) to be stored in my data-object as operation. my chosen approach in the example (use row-key) does not work.

export default {
  data () {
    return {
      userData: {
        operation: {},
        role: '',
        position: '',
        sender: '',
        identification: ''
      },

Thank you very much!

Share Improve this question edited Mar 24, 2018 at 18:48 Sazzadur Rahman 2,9501 gold badge21 silver badges37 bronze badges asked Mar 24, 2018 at 12:39 LuGeNatLuGeNat 3091 gold badge3 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

you can use @current-change event of element io. you need to add this on table like

 <el-form-item>
  <el-table
    v-model="userData.operation"
    :data="operations"
    border
    row-key="operationId"
    **@current-change="handleCurrentChange"**
    v-if="choosingOperation"
    size="small">
    <el-table-column
      prop="operationName"
      label="Einsatz-Name">
    </el-table-column>
    <el-table-column
      prop="operationAdress"
      label="Einsatz-Adresse">
    </el-table-column>
    <el-table-column
      prop="operationStaffType"
      label="Typ">
    </el-table-column>
    <el-table-column
      fixed="right"
      label="Optionen"
      width="120">
      <template slot-scope="scope">
        <el-button
          @click="userData.operation = operations[operationID]"
          type="text"
          size="small">
          Wählen
        </el-button>
      </template>
    </el-table-column>
  </el-table>
</el-form-item>

and then you will get current selected row value like

handleCurrentChange(val) {
    this.currentRowObject = val;
}
发布评论

评论列表(0)

  1. 暂无评论