vue.js - Vue - 在运行功能之前检查数据已设置
问题描述
data
调用函数时,我对更新所用的时间有疑问。
In the example below, when an option is selected, the plugin sets the element 'inputs.example' (I can see this on in the Vue Tools) to the option picked, when the option is picked it triggers a function ( triggerFunction()
), however似乎该功能在应用程序有时间设置数据之前被触发。结果,我得到了“空”数据,即使它似乎可用。
如何确保在函数运行之前设置数据?
谢谢。
落下
<Multiselect
v-model="inputs.example"
:options="options"
@select="triggerFunction(options.vendorOptions)">
</Multiselect>
功能
triggerFunction() {
if (this.inputs.example != null) {
fetch(`${API_URL}api/v1/endpoint/${this.inputs.example._id}`, {
method: "GET",
headers: {
authorization: `Bearer ${localStorage.token}`
}
})
.then(res => res.json())
.then(output. => {
console.log(output);
});
} else {
console.log("No Option Selected";
}
}
解决方案
推荐阅读
- python-3.x - Python3 beautifulsoup4 和 selenium
- powershell - 一个或多个失败时的 foreach 写入输出
- php - 如何检查是否选择了一个或多个文件进行文件上传
- r - 如何在 R 中重新排列数据框
- wordpress - 如何像三星一样添加woocmmerce产品功能描述(属性)
- statistics - 如何在使用SPSS的案例对照研究中复制案例集中的数据?
- java - 从市场数据增量刷新获取值时出错
- linux - 了解 tpcdump -d 选项
- linux - GCE Linux VM Can't access peer VPN hosts
- c++ - 查找给定数字的可能解码次数(动态编程)