Swap for a different Lightning cable, and see if that works.
Look for and carefully remove any debris found in the Lightning socket.
Try the iPhone and the current Lightning cable with a different charger, and see if it works there.
If the problem stays with the iPhone, get the iPhone looked at.
If the problem moves with the cable, replace the cable.
If the problem is with the computer’s USB port, remove other USB connected devices (except for the iPhone, and any keyboard and mouse in use) and try again. Then try restarting the computer, and try a different port.
If the problem is lint or fuzz in the Lightning socket, remove the debris.
To get the iPhone looked at, use the Get Support link in the upper right of this webpage.