十六岁少女日记

一些有意义的代码片断

2023-05-23  本文已影响0人  林家小珊

精典代码片断:

```

复杂的状态判断

<template v-slot="{row}">

  <el-tag :type="row.status == 0 ? 'success' : row.status == 1 ? 'danger' : 'warning'">

    {{row.status == 0 ? '历史' : row.status == 2 ? '预备' : '当前'}}

  </el-tag>

</template>

```

```

先切割然后在拼接

scope.row.userList.split(',').join(',')

```

```

表格套下拉选择框

<template slot-scope="scope">

  <el-select v-model="scope.row.name" placeholder="请选择" @change="handleNameChange(scope.row)">

    <el-option v-for="item in List" :key="item.id" :label="item.label" :value="item.name"></el-option>

  </el-select>

```

```

切割一个字符串,然后利用元素在另一个对象区配返回成新对象

const userList = row.userList.split(',')

this.editTableData = userList.map(name => {

  const item = this.List.find(user => user.name === name)

  return {

    name: item.name,

    age: item.age,

    permission: item.permission,

    phone: item.phone

  }

})

```

```

// 保存当前修改的行,表格一行记录起来的方法,这一行在别的地方需要用

  this.currentIndex = this.personList.indexOf(row)

  console.log("保存到几行,记录行号" + this.currentIndex)

},

```

上一篇下一篇

猜你喜欢

热点阅读