Anti-idiotype vaccines utilize idiotype-anti-idiotype network theory, eliminating the need for external antigens as vaccine candidates. Especially for dangerous pathogens, they were safer because they did not contact the live pathogenic microorganisms. However, developing anti-idiotype vaccines with traditional monoclonal and polyclonal antibodies is complex and has a high failure rate. We present a novel, universal, simple, low-cost strategy for producing anti-idiotype vaccines with nanobody technology. Using a neutralization antibody against PCV2-Cap, a nanobody (Ab2) was successfully produced and could mimic the neutralizing epitope of PCV2-Cap. The nanobody can induce protective immune responses against PCV2 infection in mice and pigs. It highlighted that the anti-idiotype vaccine using nanobody has a very good application in the future, especially for dangerous pathogens.