If I have a stationary base, I do similar to what Mantar said, and put a couple nail board traps in front of the door when I enter and exit.
If I am in a mobile base I just don’t get to close to NPCs without having the means to drive away before they can come and try to loot my vehicle. I just drive close to them and talk to them and try to get them to join, and if they don’t join, I drive away faster than they can run up to me.
If they do end up looting my vehicle somehow, I either kill them or do the mission they want me to do. Then I get them to join me and give it back (they usually will follow you and trade willingly once you do complete the mission).