When the germs/virus/whatever enters your body, your body's immune system fights the infection. The purpose of the vaccine is to help your body's immune system win the fight.
When the vaccine doesn't work, you get sick. With COVID, having been vaccinated helps your body deal with the illness better even if you get sick.
But just being in the presence of COVID and breathing in some virus doesn't mean you are now sick. The vaccine can prevent the illness from taking hold.