A nitrogenous heterocyclic compound, a preparation method, an intermediate, a composition, and an application. The present invention provides a nitrogenous heterocyclic compound as represented by formula I, pharmaceutically acceptable salts thereof, enantiomers thereof, diastereoisomers thereof, tautomers thereof, solvates thereof, metabolites thereof, or prodrugs thereof. The compound has high inhibitory activity against ErbB2 tyrosine kinase, has good inhibitory activity against human breast cancer cells BT-474, human gastric cancer cells NCI-N87 and the like with high expression of ErbB2, and in addition has relatively weak inhibitory activity against EGFR kinase, that is, the compound is an EGFR/ErbB2 double target inhibitor that attenuates EGFR kinase inhibitory activity or a small-molecule inhibitor having selectivity for an ErbB2 target. (I)