Hi there and welcome. Well, my own sons have a gag reflex that gets a work out when they have a cough. I do as well actually. I gag easily and often gag when coughing and sometimes do vomit. Ugh. No fun.
coughs are tough and can linger. A virus most likely caused the cough. Does your child have a runny nose, watery eyes still? Those are more like cold symptoms then a cough develops due to the nasal drainage and dripping of sinuses. Other viruses cause coughs. These coughs can linger for a month! At night and when a child exerts themselves doing something like running, it is usually worse. It eventually goes away.
However, some viruses turn into secondary infections. This is when something like an ear infection or bronchitis become the problem and a child can cough with either of these especially bronchitis. Often they'll have a fever with those too and a general worsening of symptoms. When this is the case, absolutely take your child to the doctor as they may need antibiotics to clear it up.
For a general cough, you can put your child in a steamy shower or just sit in a bathroom with hot water running to create steam, use a humidifier when sleeping, and I do occasionally use a cough medicine for kids along with a spoonful of honey.
When in doubt, check with your child's doctor though. The vomiting upon coughing isn't abnormal but if the persistent cough is worrying you, you can get it checked. good luck