VueJS 如何在继续之前等待 axios 数据
P粉520204081
P粉520204081 2023-08-26 10:34:00
0
1
359
<p>我有这段代码,它应该将数据解析为变量,然后发送一个发布请求。</p> <p>问题是,我需要 API 中的一个属性,但我不知道如何才能等待它返回。</p> <pre class="brush:php;toolbar:false;">addFieldData(data, generatorData) { this.populateModel(data); console.log(this.model); this.$axios.post('data/webform/fields', this.model) .then(res =&gt; { console.log(res); this.$notify({ group: &quot;app&quot;, title: this.$t(&quot;general.success&quot;), text: this.$t(&quot;general.action_has_been_processed&quot;), type: &quot;info&quot; }); }).catch(error =&gt; { this.$notify({ group: &quot;app&quot;, title: this.$t(&quot;general.error&quot;), text: this.$t(&quot;general.error_occured&quot;), type: &quot;error&quot; }); console.log(error); }); }, populateModel(data) { this.model.label = data.label ?? {}; this.model.hint = data.placeholder ?? {}; this.model.attributes = data.attributes ?? {}; this.model.maxlength = data.maxlength ?? 0; this.model.position = this.getFieldPosition(); this.model.required = data.required ?? true; this.model.visible = data.visible ?? true; this.model.disabled = data.disabled ?? false; this.model.style_classes = data.style_classes ?? &quot;&quot;; this.model.model = data.model ?? &quot;&quot;; this.model.default = data.default ?? &quot;&quot;; this.model.input_type = data.input_type ?? &quot;&quot;; this.model.hint = data.hint ?? &quot;&quot;; this.model.help = data.help ?? &quot;&quot;; this.model.type = data.type; }, async getFieldPosition() { const res = await this.$axios.get('/data/webform/' + this.idWebform + '/itemsCount'); this.model.position = res.data.data.count + 1; return res.data.data.count; },</pre> <p>在 addFieldData 中,我调用 populateModel,它应该从 API 获取位置,但在 getFieldPosition 返回数据之前调用 post 请求。</p> <p>我想尝试先等待 getFieldPosition,然后发送 post 请求。</p>
P粉520204081
P粉520204081

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!