There are two reasons a dog may throw up mucus: it may be regurgitating food that is just covered in mucus, or it may be hacking up mucus due to coughing. Generally, if the dog's chest and ribs move visibly while it expels the mucus, it's related to coughing; if it just comes out without effort, it is likely a regurgitation of food.
Regurgitation is usually due to a glitch in the valve between the esophagus and stomach, or a glitch in the esophagus or throat. When it occurs, the dog may gag and cough, but there is usually no bile present in the dog's vomit.
When dogs hack up mucus and foaming liquids from coughing, they may have a problem with the esophagus, heart, sinuses or respiratory system. Other causes of vomiting in dogs include diabetes, kidney failure and digestive issues. Vomit that is just clear or yellow may be indicative of acute gastritis, intestinal blockage, pancreatitis or other problems.
Evaluation by a vet for vomiting is recommended. Most cases of acute vomiting resolve on their own within 48 hours of resting the stomach. Prolonged vomiting should be addressed by a vet and a treatment plan devised to deal with symptom control and management of any condition causing the vomiting.