春节将至,iView 近期的一些更新

春节将至,iView 也带来了戊戌年最后的一些更新。

首先是上周更新的 3.2.2 版本,这个版本更新了近 20 项内容,主要解决核心版本 3.2 中 Select 组件的一些问题。3.2.2 版本是非常值得更新的,首先是 3.2 开始,Table 组件支持了 slot-scope 写法,也就说,在表格组件中自定义列模板,不用再使用 Render 函数了(当然 3.2 仍然是兼容 Render 的,并没有废弃,所以不影响之前的代码)。比如一个修改当前行数据的示例,现在可以这样写:

<template>
  <Table :columns="columns" :data="data">
    <template slot-scope="{ row, index }" slot="name">
      <Input type="text" v-model="editName" v-if="editIndex === index" />
      <span v-else>{{ row.name }}</span>
    </template>

    <template slot-scope="{ row, index }" slot="age">
      <Input type="text" v-model="editAge" v-if="editIndex === index" />
      <span v-else>{{ row.age }}</span>
    </template>

    <template slot-scope="{ row, index }" slot="birthday">
      <Input type="text" v-model="editBirthday" v-if="editIndex === index" />
      <span v-else>{{ getBirthday(row.birthday) }}</span>
    </template>

    <template slot-scope="{ row, index }" slot="address">
      <Input type="text" v-model="editAddress" v-if="editIndex === index" />
      <span v-else>{{ row.address }}</span>
    </template>

    <template slot-scope="{ row, index }" slot="action">
      <div v-if="editIndex === index">
        <Button @click="handleSave(index)">保存</Button>
        <Button @click="editIndex = -1">取消</Button>
      </div>
      <div v-else>
        <Button @click="handleEdit(row, index)">操作</Button>
      </div>
    </template>
  </Table>
</template>
<script>
  export default {
    data () {
      return {
        columns: [
          {
            title: '姓名',
            slot: 'name'
          },
          {
            title: '年龄',
            slot: 'age'
          },
          {
            title: '出生日期',
            slot: 'birthday'
          },
          {
            title: '地址',
            slot: 'address'
          },
          {
            title: '操作',
            slot: 'action'
          }
        ],
        data: [
          {
            name: '王小明',
            age: 18,
            birthday: '919526400000',
            address: '北京市朝阳区芍药居'
          },
          {
            name: '张小刚',
            age: 25,
            birthday: '696096000000',
            address: '北京市海淀区西二旗'
          },
          {
            name: '李小红',
            age: 30,
            birthday: '563472000000',
            address: '上海市浦东新区世纪大道'
          },
          {
            name: '周小伟',
            age: 26,
            birthday: '687024000000',
            address: '深圳市南山区深南大道'
          }
        ],
        editIndex: -1,  // 当前聚焦的输入框的行数
        editName: '',  // 第一列输入框,当然聚焦的输入框的输入内容,与 data 分离避免重构的闪烁
        editAge: '',  // 第二列输入框
        editBirthday: '',  // 第三列输入框
        editAddress: '',  // 第四列输入框
      }
    },
    methods: {
      handleEdit (row, index) {
        this.editName = row.name;
        this.editAge = row.age;
        this.editAddress = row.address;
        this.editBirthday = row.birthday;
        this.editIndex = index;
      },
      handleSave (index) {
        this.data[index].name = this.editName;
        this.data[index].age = this.editAge;
        this.data[index].birthday = this.editBirthday;
        this.data[index].address = this.editAddress;
        this.editIndex = -1;
      },
      getBirthday (birthday) {
        const date = new Date(parseInt(birthday));
        const year = date.getFullYear();
        const month = date.getMonth() + 1;
        const day = date.getDate();
        return `${year}-${month}-${day}`;
      }
    }
  }
</script>
复制代码

这种写法要比 Render 更简单明了,也更符合 Vue.js 的语法。

3.2.2 版本是对 3.2 版本造成的一些问题修复,所以建议大家直接更新到最新的 3.2.2 版本。

除了 iView 组件库,iView 文档也做了一些更新。

  1. 支持了从 iView Developer 一键授权登录:

    登录后,从 iView 文档就可以接收到通知,如果你是社区付费会员,还可以选择屏蔽赞助商广告。之后 iView 所有的生态产品,都将使用这样的一键授权登录,比如 iView Run 也将集成登录,这样用户就可以保存示例了。

  2. 文档新增了提问题写示例提 Issues 的快捷入口:

  3. 文档将额外的设置和社区信息整合到了一个抽屉里:

  4. 现在文档中所有的示例,都支持直接在 iView Run 中打开了:

    iView Run 中的预览效果更接近一个 .vue 文件,相比 jsFiddle 要更简单操作,而且对于中国用户来说,访问速度也是极快的,因为 iView 的主要服务都使用了全球 CDN 加速,几乎是秒开的。这些优质的体验会增加不少运营成本,但为了用户着想,是必须要支持的。

新年前 iView 不会再有版本更新了,不过马上也会更新文档首页新春版(放心,我们的组件库代码没有彩蛋!)。

最后,iView 预祝大家 2019 年快乐多一点,bug 少一点!

猜你喜欢

转载自juejin.im/post/5c484011e51d4542253ffc93
今日推荐