Because they’re a part of a healthy living plant.
When a fruit or a vegetable is still attached to the plant, it’s still growing, getting nutrients, getting damage repaired, it’s still a living growing healthy thing.
As soon as it falls off/is plucked, it stop getting replenished and cannot fight the rot as well.
It’s the same reason why your finger stays nice and healthy when starched to your body, but if you cut your finger off it won’t last very long before it starts to rot.
Latest Answers