Vietnamese forces have lost a couple battles with China over South China Sea islands. Vietnam needs to be able to win one of those to retain their footholds in the South China Sea in the face of Chinese territorial claims in defiance of international law.
Yes, China knocked the Vietnamese around a couple times over South China Sea islands.
But resistance to China is not futile. As I've noted regarding the Philippines problem with China, preparing for a battle with China is doable given that escalating to war to win is not necessarily in China's interest if it disrupts trade and reputation. China wants any fight to be over with fast and if small nations can deny China a quick win, the small nations could win the militarized confrontation.
And Vietnam has the advantage of having bested the Chinese effort to "punish" Vietnam in the 1979 border war.
Granted, the battle-hardened Vietnamese army of that era is long gone. And China's army is no longer as primitive as it was then. But with work, Vietnam could hold off the Chinese and make them pay a high price if China tries to escalate a lost battle at sea to a short and glorious "punishment" war on the border.
And of course, the longer and bigger a fight gets, the more China has to worry that Japan, India, Australia, and America would be drawn into the fight, at least with weapons, logistics, and intelligence.
So working to win a battle and making the cost of war too high for China to pay could work for smaller powers like Vietnam that don't wish to cave in to Chinese demands to vacate the South China Sea.