vue.js - 如何防止多个电子邮件字段只接受一个建议?
问题描述
我有一组电子邮件字段。当我开始输入一个时,它会给我一些建议。然后我选择一个建议,并为所有电子邮件字段设置它。有没有办法为一个电子邮件字段选择电子邮件建议,即使页面上可能有多个?
这是一个 vue.js 应用程序。这是电子邮件字段的模板:
<v-layout row wrap v-for="(item, index) in prop.roles" :key="index">
<v-flex mb-4>
<div class="ath-container">
<div class="ath-controls-container mb-2">
<v-text-field
:id="'email-' + index"
class="d-inline-block ath-email-field"
outline
label="Email"
v-model="item.email"
placeholder="username@example.com"
:rules="[v => !!v || 'Email is required',
v => /.+@.+/.test(v) || 'Email is invalid' ]"
maxlength="255"
required>
...
</div>
</div>
</v-flex>
</v-layout>
有一个“添加”按钮,允许用户添加更多电子邮件字段。但我希望在从弹出列表中选择建议的电子邮件时独立对待它们。谢谢。
编辑:请求数据和方法块。
data() {
return {
isValid: false,
isCompany: false,
prop: {
companyName: null,
hasAdditionalTitleHolders: null,
roles: [{
email: null,
notifying: false
}],
isMarried: null,
hasSpouse: null
},
dowerRightsFilenameData: null,
rafId: 0, // request animation frame ID (see animateStatusBarIfInView() below)
notifyingAll: false
}
}
methods: {
onDowerRightsFormPicked(e) {
this.dowerRightsFilenameData = e.target.files[0].name;
this.$emit('dower-rights-form-picked', e);
},
deleteDowerRightsForm() {
this.dowerRightsFilenameData = '';
this.$emit('delete-dower-rights-form');
},
animateStatusBarIfInView() {
for (let index = 0; index < this.prop.roles.length; index++) {
if (this.$refs['ath-status-bar-' + index] && this.$refs['ath-status-bar-' + index][0]) {
const athStatusBar = this.$refs['ath-status-bar-' + index][0];
const ath = this.prop.roles[index];
if (this.isInViewport(athStatusBar)) {
let className = 'ath-status-bar-init';
if (ath.acceptedAt) {
className = 'ath-status-bar-accepted';
} else if (ath.verifiedAt) {
className = 'ath-status-bar-verified';
} else if (ath.accountCreatedAt) {
className = 'ath-status-bar-account-created';
} else if (ath.invitedAt) {
className = 'ath-status-bar-invited';
}
athStatusBar.classList.add(className);
}
}
}
// repeat:
if (this.rafId) window.cancelAnimationFrame(this.rafId);
this.rafId = window.requestAnimationFrame(this.animateStatusBarIfInView);
},
isInViewport(element) {
const rec = element.getBoundingClientRect();
return rec.top < (window.innerHeight || document.documentElement.clientHeight) && rec.bottom > 0;
},
notifyAllAths() {
this.notifyingAll = true;
let index = 0;
const allIndexes = this.prop.roles.map(ath => index++);
this.$emit('notify-aths', allIndexes);
}
}
解决方案
推荐阅读
- c# - JObject 反序列化到接口
- html - 表格在前景中左对齐
- java - 从另一个类启动并稍后恢复/显示应用程序后暂停/隐藏 JavaFX 应用程序
- c# - 在 Visual Studio 社区上使用 SDK android 后关闭电脑时蓝屏
- python - 使用 Tkinter 和 python 的交互式元素周期表
- azure - 未找到 ARM 模板部署资源命名空间
- c++ - 如何以 Big-O 表示法计算平均渐近运行时间?
- vba - 在 Access 中创建表单以供用户关联两个数据集的替代方法
- php - 子数组中的总和
- entity-framework - 技术设计问题:应该在 DAL、Business 还是 ViewModel 层?