Ant Design Vue教程

Ant Design Vue AutoComplete 通过自定义选项search实现如自动补充邮箱后缀功能

node.js webpack开发方式

<template>
  <a-auto-complete style="width: 260px" @search="search" placeholder="输入字母看看">
    <template slot="dataSource">
      <a-select-option v-for="email in result" :key="email">{{email}}</a-select-option>
    </template>
  </a-auto-complete>
</template>
<script>
  export default {
    data() {
      return {
        result: [],
      };
    },
    methods: {
      search(value) {
        let result;
        if (!value || value.indexOf('@') >= 0) {
          result = [];
        } else {
          result = ['ixst.com', 'gmail.com',
           '163.com', 'qq.com'].map(domain => `${value}@${domain}`);
        }
        this.result = result;
      },
    },
  };
</script>

浏览器方式

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Ant Design Vue AutoComplete 自动补充邮箱后缀例子</title>
    <script src="https://www.itxst.com/package/vue/vue.min.js"></script>
    <script src="https://www.itxst.com/package/ant-design-vue/antd.min.js"></script>
    <link href="https://www.itxst.com/package/ant-design-vue/antd.min.css" rel="stylesheet" />
    <style>
        body {
            padding-top: 10px
        }
        .ant-pagination-item-link.red {
            color: red;
            padding-left: 6px;
            padding-right: 6px;
        }
    </style>
</head>
<body>
<div id="app">
  <a-auto-complete style="width: 260px" @search="search" placeholder="输入字母看看">
    <template slot="dataSource">
      <a-select-option v-for="email in dataSource" :key="email">{{email}}</a-select-option>
    </template>
  </a-auto-complete>
</div>
<script>
var app = new Vue({
    el: '#app',
     data() {
      return {
         dataSource: [],
      };
    },
    methods: {
     search(value) {
          let result;
          if (!value || value.indexOf('@') >= 0) {
            result = [];
          } else {
            result = ['ixst.com', 'gmail.com', '163.com','qq.com'];
            for(var i=0;i<result.length;i++)
            {
              result[i]=value+"@"+result[i]
            }
          }
          this.dataSource = result;
        },
    },
});
 </script>
</body>
</html>

例子

Catalog
快速入门 Dropdown 下拉菜单 Menu 导航菜单 Pagination 分页 Steps 步骤条 AutoComplete 自动填充 AutoComplete 自动完成组件 AutoComplete 前端筛选函数 AutoComplete 自定义选项 AutoComplete Ajax服务器端数据 AutoComplete 查询模式 AutoComplete 属性列表 AutoComplete 事件 AutoComplete 方法列表 Cascader 级联选择 Checkbox 多选框 DatePicker 日期选择框 Input 输入框 InputNumber 数字输入框 Mentions 提及 Radio 单选框 Rate 评分组件 Select 下拉框 Slider 滑动输入条 Switch 开关