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="http://www.itxst.com/package/vue/vue.min.js"></script>
    <script src="http://www.itxst.com/package/ant-design-vue/antd.min.js"></script>
    <link href="http://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>

例子