Since the time of Andrew Jackson's run for the presidency in 1828, individual political parties have had the job of filling any vacancy on their national ticket, either that of their presidential or vice-presidential candidate.
If one of their candidates vacates the ticket after they are nominated, either because of death or withdrawal, the party selects a replacement.
Both the Republican and the Democrat parties have rules in their bylaws governing how to fill the vacancy.
The Party Chair calls a meeting of the National Committee, and the Committee members at the meeting vote to fill the vacancy on the ticket. A candidate must receive a majority of the votes to win the party's nod.
The same process would happen if the vacancy were to occur after the general election but before the Electoral College voting.
If a vacancy should occur on the winning ticket, it would then be the party's responsibility to fill it and provide a candidate for whom their electors could vote.
http://teachinghistory.org/history-content/ask-a-historian/20431