Android Devices cannot be affected in any way when you connect it to a computer (atleast when connected in MTP mode)..
There might be a possibility that you'll get affected, that too only when USB Debugging (ADB mode) is ON, because there might be a chance that there's a virus in your computer that can install a payload virus application directly (without your knowledge) via the ADB mode to your device.
That app might be a type of virus that periodically displays advertisements, or can be installed as a payloaded (modded) update to an existing application (like a Browser or even Banking app) (with same package name) in your device that can track every info you provide to the app (even the user credentials you provide, like username and password). Or in the worst case, it can be a exploit app that can install itself or its other apps as system app, making it impossible to uninstall (unless you root your device).
So switch OFF ADB mode when not used or when you're not working in a trustable computer.
When your device is connected in USB Mass Storage Mode (which is removed since KitKat), there's a chance that a virus in your computer might place crafted virus files in the removable disk (popular viruses like autorun.inf, New Folder .exe, Shortcut virus, etc.), but that won't affect your Android device in any way. Only when you connect the device to another computer (in UMS mode), there's a chance that the computer might get affected.
Other than these, I don't think there's anything harmful when connected to computer, AFAIK.