Answer the question
In order to leave comments, you need to log in
How to avoid switch when implementing a component that works with different APIs/entities in VueJS?
There is a component that is a form for uploading scans. The scan is attached to a document, and documents are of different types and have different APIs/endpoints for them. Accordingly, visually the component looks the same, but it should load scans at different URLs.
One solution is to pass type to the component, and write something like this in the component itself:
switch (this.type) {
case 'oneDoc':
oneDocApi.uploadScan(...); return
case 'anotherDoc':
anotherDocApi.uploadScan(...); return
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question