My son started making himself throw up when he was still an infant. (Maybe 6 or 7 months old.) He learned to stand up and throw up into a toilet long before he learned to walk or go potty in the toilet. (Not one of my prouder moments as a parent.)
My mother swore up and down that Alex was not doing the barfing to get attention, but it became quickly apparent that he was working himself into a tantrum and throwing up so that he could get attention. So, we stopped giving it to him.
We would yank him out of his bed (or wherever he was playing), deposit him in the bathroom and leave him there to barf. When he got older, he also had to help clean up. We didn't hug him and coddle him when he would barf. We just monitored from outside the bathroom and cleaned him up quickly when he was done.
As he got into toddler-hood, this became much less gratifying for him. Especially since he had to help clean up. He eventually stopped tantruming into barf-fests.
He does have an easy gag reflex, and he will gag when he smells something bad, eats something he doesn't like, etc. But, we don't coddle him or reward him for that behavior, so now he is making an effort to stop.
Give your granddaughter time. It's not going to stop overnight, but if she is really doing it for attention, it will pass.
Good luck!