正则判断输入的是数字还是中文

阅读 21

2022-02-15

    async remoteMethod(query) {
      if (query !== '') {
        if (/[\u4e00-\u9fa5]/.test(query)) {
          const res = await getCinemaList({
            pageNum: 1,
            cinemaName: query
            // zzCode: query
          });
          this.loading = true;
          this.cinemaOptions = [];
          for (const item of res.data.list) {
            this.cinemaOptions.push({
              label: item.name,
              value: item.id
            });
          }
          this.loading = false;
        } else {
          const res = await getCinemaList({
            pageNum: 1,
            zzCode: query
          });
          this.loading = true;
          this.cinemaOptions = [];
          for (const item of res.data.list) {
            this.cinemaOptions.push({
              label: item.name,
              value: item.id
            });
          }
          this.loading = false;
        }
      } else {
        this.cinemaOptions = [];
      }
    },```

精彩评论(0)

0 0 举报