My humble answer: An asthma attack occurs because you inhale something that your immune system responds to, such as dust mites, mold, cockroach urine, chemicals, etc. One part of this response is to cause your goblet cells to secrete mucus in order to trap the invading microbes. As the disease progresses you may even develop an abnormally large amount of goblet cells. So when you have an asthma attack mucus may be excessive.
One of the interesting things about asthma sputum is it is usually sterile and white, as I explain here.