The need to throw up may be set off by a number of things, including food allergies, pregnancy, migraines, certain medications, the stomach flu, and more (via Penn Medicine). While certain warning signs, like gagging, may make sense, the connection between sweating and vomiting may seem a little less obvious.
As you begin to vomit, the body increases saliva production in the mouth (via BBC Science Focus). This serves as a protective coating for your mouth and teeth against impending stomach acid exposure. The body then triggers you to inhale deeply to prevent vomit from entering the lungs. Your diaphragm then creates pressure in the stomach through a series of short, sharp contractions, which also prompts dry heaving. The body then seals off the entryway to the lungs as your stomach muscle contract and the exit at the bottom of the stomach closes shut.
The last step is where the sweating comes in. As your sympathetic nervous system activates, your heart rate increases and the body releases sweat to then cool itself down.