VueJS 如何在继续之前等待 axios 数据
P粉520204081
P粉520204081 2023-08-26 10:34:00
0
1
362
<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 => { console.log(res); this.$notify({ group: "app", title: this.$t("general.success"), text: this.$t("general.action_has_been_processed"), type: "info" }); }).catch(error => { this.$notify({ group: "app", title: this.$t("general.error"), text: this.$t("general.error_occured"), type: "error" }); 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 ?? ""; this.model.model = data.model ?? ""; this.model.default = data.default ?? ""; this.model.input_type = data.input_type ?? ""; this.model.hint = data.hint ?? ""; this.model.help = data.help ?? ""; 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学习者快速成长!