We have a relatively elderly Miniature Schnauzer (11 years old now).
When she was younger, she used to pretty much ignore other dogs when on and off the leash. She's not really one for socialising, she'd much rather do her own thing, and this has always been the case.
Gradually over the past few years, she's been more yappy at other dogs while on the leash. It started off with being aimed at smaller dogs (Jack Russells and the like), but now she barks at anything with four legs, and at any noise coming from the footpath behind our yard.
She's healthy for her age, but the vet said she might be showing early signs of joint pain, although she walks/runs just fine and without reluctance).
We could try distracting with treats, but she often sees/hears other dogs before us, so offering treats while she's yapping might end up reinforcing unwanted behaviour.