There are relatively few reports on the combination of viologen and polyoxometalates (POMs). Herein, we successfully synthesized three viologen−POM-based compounds by in situ transformation of ligands under hydrothermal conditions, namely, {M II (1,4-cby) 2 [H 2 (γ-Mo 8 O 26 )]}•nH 2 O (1: M = Ni, n = 4; 2: M = Co, n = 6), and [Ni II (1,3Isostructural compounds 1 and 2 exhibit two-dimensional (2D) layer structures with POMs as linking nodes, while compound 3 shows a one-dimensional (1D) metal−organic chain with dissociative POM anions. When the temperature increases, compounds 1−3 show good reversible thermochromism properties and also have a fluorescence quenching effect. Moreover, compounds 1−3 can also be used as detectors for organic amines, especially in the atmosphere of ammonia, ethylenediamine, and diethylamine with an obvious discoloration effect. In addition, compound 1 was used as a material for the preparation of memristors with superior properties (distinct temperature-adjusted resistive switching properties). It shows bipolar resistive switching (RS) behavior at different temperatures of 20, 50, and 100 °C. The results show that the 1-based memristor has good thermal stability, which is important for high-temperature environment applications. It also shows that crystalline viologen−POM-based compounds are ideal candidates for making memristors.