我有一個表單,將VueJS鏈接到Strapi CMS資料庫。長話短說,如果我輸入一個不存在的組織,它應該允許我創建該組織并輸入EIN。一切都很正常,直到我點擊提交。
JSON資料顯示它拉入了組織名稱。但是一旦我到了EIN欄位,就好像組織名稱被移回了引數中,然后EIN就沒有被拉進來。下面是相關的代碼,如果有人能發現任何導致這個問題的錯誤/問題。
我得到的錯誤是:
在v-on處理程式(Promise/async)中出現錯誤。"ReferenceError: result is not defined"
我只分享代碼的特定部分,因為無論如何,它需要整個專案的運行。
謝謝你!
VUE:
<v-col cols="12">
<v-autocomplete
v-if="!newOrg"
v-model="注冊.組織"
:items="foundOrgs"
:loading="加載中"
:search-input.sync="searchOrgs"
cache-items
渴望
概述
密集
:disabled="發送"
item-text="name"
item-value="id"
label="組織名稱"
placeholder="開始鍵入搜索"
autocomplete="關閉"
>
<模板 v-slot:no-data>
<v-list-item v-if="!loading">
<v-list-item-title>
沒有找到組織。
<a @click="addNewOrg">點擊這里</a>
來添加它
</v-list-item-title>
</v-list-item>
</template>
</v-autocomplete>
<v-text-field
v-if="newOrg"
label="組織"
name="組織"
type="text"
概述
密密麻麻的
:disabled="發送"
v-validate.disable="'required'"
:error-messages="errors.collect('Organization')"
data-vv-name="組織"
需要
v-model="注冊.組織.名稱"
></v-text-field>
<v-text-field
v-if="newOrg"
label="EIN"
name="EIN"
type="text"
概述
密密麻麻的
:disabled="發送"
v-validate.disable="'required'"
:error-messages="errors.collect('EIN')"
data-vv-name="EIN"
需要
v-model="registration.organization.ein"
></v-text-field>
<v-btn
:disabled="發送"
type="提交"
:loading="發送"
class="main-btn"
>注冊</v-btn
>
SCRIPT:
export default {
name: "Registration",
data() {
回傳 {
注冊。{
firstName: "",
lastName: "",
電子郵件。"",
密碼:""。
組織。{
name: "",
ein: "",
},
},
loading: false,
newOrg: false,
foundOrgs: [],
searchOrgs: null,
發送: false,
logo: logo,
};
},
watch: {
searchOrgs(val) {
val = val.trim();
if (!val) {
this.foundOrgs = [];
回傳。
}
this.loading = true;
Vue.$organizationService.autocomplete(val).then((orgs) => {
this.foundOrgs = orgs;
this.loading = false;
});
},
},
方法: {
addNewOrg() {
this.registration.organization = { name : this.searchOrgs, ein : null };
this.newOrg = true;
},
async register() {
try {
let result = await this.$validator.validateAll();
if (!result) {
回傳結果。
}
} catch (err) {
回傳。
}
if (!result) {
Vue.$eventBus.$emit("notifyUser", "Fix the invalid fields") 。
回傳false。
}
this.sending = true;
嘗試 {
this.registration.username = this.registration.email;
await Vue.$userService.register(this.registration);
this.$router.push("Login")。
} catch {
console.log("這里發生了什么")。
}
},
},
};
uj5u.com熱心網友回復:
問題是你試圖訪問result (let) 范圍外的。你在try塊內定義了result。在外面定義let result將解決你的問題。
讓結果
try {
result = await this.$validator.validateAll();
if (!result) {
回傳結果。
}
} catch (err) {
回傳。
}
if (!result) {
Vue.$eventBus.$emit("notifyUser", "Fix the invalid fields") 。
回傳false。
}
uj5u.com熱心網友回復:
EIN文本欄位上的v-model系結應該是registration.organization.ein而不是registration.ein
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/332733.html
標籤:
下一篇:回收站專案在第一時間沒有顯示
