美文网首页十六岁少女日记
一些有意义的代码片断

一些有意义的代码片断

作者: 林家小珊 | 来源:发表于2023-05-23 17:19 被阅读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)

    },

    ```

    相关文章

      网友评论

        本文标题:一些有意义的代码片断

        本文链接:https://www.haomeiwen.com/subject/dhixedtx.html