A time-frequency resource switching method, comprising: receiving, by a first device, a first resource switching message sent by a second device, wherein the first device and the second device belong to a same Neighbor Awareness Network, NAN, service group, the first resource switching message is used to instruct devices in the NAN service group to perform time-frequency resource switching, the first resource switching message comprises first time-frequency resource information, and the first time-frequency resource information is used to indicate a first time-frequency resource satisfying a time-frequency resource switching requirement of the second device; determining, by the first device, a second time-frequency resource in the first time-frequency resource, wherein the second time-frequency resource is a time-frequency resource satisfying a time-frequency resource switching requirement of the first device; and sending, by the first device, a second resource switching message, wherein the second resource switching message comprises second resource information, and the second resource information is used to indicate the second resource, wherein the first time-frequency resource comprises a first target time-frequency resource and at least one first candidate time-frequency resource, and the second time-frequency resource comprises a second target time-frequency resource, and the determining, by the first device, a second time-frequency resource in the first time-frequency resource comprises: if the first target time-frequency resource satisfies the time-frequency resource switching requirement of the first device, determining, by the first device, the first target time-frequency resource as the second target time-frequency resource, and if the first target time-frequency resource does not satisfy the time-frequency resource switching requirement of the first device, determining, by the first device, a time-frequency resource in the at least one first candidate time-frequency resource as the second target time-frequency resource, wherein the second target time-frequency resource is a time-frequency resource that is in the at least one first candidate time-frequency resource, that satisfies the time-frequency resource switching requirement of the first device, and that has optimal quality. receiving, by a first device, a first resource switching message sent by a second device, wherein the first device and the second device belong to a same Neighbor Awareness Network, NAN, service group, the first resource switching message is used to instruct devices in the NAN service group to perform time-frequency resource switching, the first resource switching message comprises first time-frequency resource information, and the first time-frequency resource information is used to indicate a first time-frequency resource satisfying a time-frequency resource switching requirement of the second device; determining, by the first device, a second time-frequency resource in the first time-frequency resource, wherein the second time-frequency resource is a time-frequency resource satisfying a time-frequency resource switching requirement of the first device; and sending, by the first device, a second resource switching message, wherein the second resource switching message comprises second resource information, and the second resource information is used to indicate the second resource, wherein the first time-frequency resource comprises a first target time-frequency resource and at least one first candidate time-frequency resource, and the second time-frequency resource comprises a second target time-frequency resource, and the determining, by the first device, a second time-frequency resource in the first time-frequency resource comprises: if the first target time-frequency resource satisfies the time-frequency resource switching requirement of the first device, determining, by the first device, the first target time-frequency resource as the second target time-frequency resource, and if the first target time-frequency resource does not satisfy the time-frequency resource switching requirement of the first device, determining, by the first device, a time-frequency resource in the at least one first candidate time-frequency resource as the second target time-frequency resource, wherein the second target time-frequency resource is a time-frequency resource that is in the at least one first candidate time-frequency resource, that satisfies the time-frequency resource switching requirement of the first device, and that has optimal quality. if the first target time-frequency resource satisfies the time-frequency resource switching requirement of the first device, determining, by the first device, the first target time-frequency resource as the second target time-frequency resource, and if the first target time-frequency resource does not satisfy the time-frequency resource switching requirement of the first device, determining, by the first device, a time-frequency resource in the at least one first candidate time-frequency resource as the second target time-frequency resource, wherein the second target time-frequency resource is a time-frequency resource that is in the at least one first candidate time-frequency resource, that satisfies the time-frequency resource switching requirement of the first device, and that has optimal quality.