Worms can obstruct the gastrointestinal (GI) tract, which can cause vomiting and/or diarrhea. If your dog vomited worms, there is a possibility that there is a heavy intestinal worm infestation. It's highly recommended that you take your dog to your vet at the soonest possible time for proper diagnosis and treatment.
More useful articles on a similar topic 👇
What does it mean when a puppy puked up worms?Do dogs automatically have worms?