异步与手表功能



下面的watch函数过滤prop.students。函数alphallinks传递prop.students的值。如何使函数等待并传递过滤后的值。就像现在一样,它在过滤之前传递值。

我正在使用合成API

watch( [search, serviceDate, currentGrade, currentHr, mealType], ([searchValue, serviceDateValue, currentGradeValue, currentHrValue, mealTypeValue])  => {
Inertia.get('/pos', {search: searchValue, serviceDate: serviceDateValue, grade: currentGradeValue, hr: currentHrValue, mealType: mealTypeValue}, {
preserveState: true,
})
alphaLinks(props.students);
});

惯性手动访问提供事件处理程序。您可以在请求之后使用onSuccessonFinish事件处理程序调用函数。不同之处在于,第一个只在请求成功时运行,而第二个只在请求成功或不成功时运行。

Inertia.get('/pos', { ...data }, {
preserveState: true,
onSuccess: (page) => {
alphaLinks(props.students);
},
// or ...
onFinish: (visit) => {
alphaLinks(props.students);
},
})

最新更新