The term "Vanity Fair" is most often associated in literary discussions with the novel Vanity Fair: A Novel Without a Hero by William Makepeace Thackeray, first published in 1847-8. It details the adventures of Becky Sharp, a young woman born to poverty and trying to better her situation using her wits and complete lack of scruples.
The source of Thackeray's title was a much earlier literary work by John Bunyan, The Pilgrim’s Progress from This World to That Which Is to Come (1678). It is a tale of a pilgrimage by the protagonist, Christian, from his home to the Celestial City, with the story of the travels of the pilgrim serving as an allegory of the progress of the soul from sin to salvation. During this pilgrimage, Christian encounters many obstacles in his journey, including the town of Vanity Fair, a commercial center devoted to worldly wealth and the accumulation of goods. The point Bunyan is making is that love of worldly possessions can endanger the soul.
Thackeray's use of the title from Bunyan lets the reader know that the novel is one about how longing for material wealth affects people's lives (negatively).
A final important note is that the term "vanity" has more than one meaning. In the twenty-first century, we normally use the term to refer to excessive personal pride. In pre-twentieth century English, "vanity" means pointlessness. Thus in the King James version of the Bible, Ecclesiastes 1:2 runs:
"Vanity of vanities," says the Preacher, "Vanity of vanities! All is vanity."
This sentence means that everything is pointless in light of our mortality. In the phrase "vanity fair," both meanings (pride, pointlessness) apply. Vanity refers to both pride (especially in wealth and material possessions) but also the phrase suggests that such pride and the material goods we accumulate in this life are indeed "vanities," trivial in comparison with the more important matters of our moral choices, inner worth, and (in the Christian context of Bunyan) eventual salvation.