Trump is just a rudderless attention whore. That translates into him "being good at appealing to his base", but that only requires a simple Pavlovian conditioning mechanism, no kind of crafty Machiavellian scheming that would belie any actual cognitive intelligence.
Trump does a thing. It gets him attention. So he does the thing more.
He randomly does variations on the thing, and also other things, and those that get him the most attention reinforce that particular behavior, and he does more of it.
Someone asked upthread whether Trump is honestly misinformed or spreading things he knows to be false, and while I think both of those things are happening, they're as a consequence of Trump spewing bullshit, in a technical sense
. Trump says whatever gets the reaction he wants to get from it, without regard for whether it's true. Sometimes that may mean saying things he knows to be false. Sometimes it may mean saying things he has no information about. Occasionally it will mean saying things that he both believes and are true. But he's not saying them because he believes them to be true, he's saying them because it's useful to say them (because it gets the reaction he wants, and gets him more attention). That they happen to be true sometimes is just fortuitous. If it's useful to say other things and those things happen to be false, or if he has no idea about their truth or falsehood, that's fine with him because he doesn't care.
That's what people are talking about with all this "post-truth politics" and such.
ETA: Someone upthread mentioned in passing his slip-up with the gun control issue, and I think that nicely illustrates this. At a meeting between Trump and lawmakers, some Democrats tentatively asked if Trump would consider having some kind of mechanism by which through due process guns could be taken away from people deemed unsafe to have them, and Trump replied something about why not just take all the guns from the bad people right away and then figure out who should get them back later. That sounds like a simple common-sense popular idea that a five-year-old would understand: no guns for bad people! Of course that's going to get Trump a positive reaction! What it got was flabbergasted surprise from both sides of the aisle and presumably a stern talking-to by his Republican handlers who issued a "correction" on his stance about gun control the next day.
Or also, look at all the promises he made on the campaign trail. He basically just said whatever anybody wanted to hear. He just happily and without qualifications promised a reporter that yeah sure of course everyone is going to be medically insured, nobody's going to be left behind, everyone will get even better health care than they have now, he's totally not going to destroy the tiny progress on that front that had just been made. I don't think he said that knowing that he intended to do the opposite, I think he said that because that's a good-sounding thing to say that will get a positive reaction from the audience -- "yes, of course you're going to keep all the good things you have now, and it's going to be even better!" -- and he didn't care if it turned out to be true or not. His Republican handlers later convinced him that their repeal of The Affordable Care Act would be that "everything you already have and more", and whether or not that turned out to be true (spoiler alert: it didn't), Trump's got to stick to the message that Trump did the good thing and made everything better because Trump is a winner all the time, so much winning, because if Trump wasn't winning at everything all the time people wouldn't like Trump and that would make Trump feel bad.
I think even the "good people on both sides" comment and hesitation to disavow support by white supremacists is ultimately because of this. Trump wants everyone to like Trump. Trump doesn't want to alienate anyone... at least, not anyone who likes Trump, or who might like Trump. Anyone who doesn't like Trump is obviously a bad person to Trump and their opinions don't count anymore because they don't like Trump and that makes them not count. It's still a form of moral bankruptcy, but I don't think Trump associates to Nazis because he really believes in their message, he associates to them because they support him. If, somehow, all the Nazis in the country turned around and became the most vocal Trump-haters (no idea how that would happen, but hypothetically), I have no doubt that Trump would become the #1 advocate for banning them from the country or whatever other abuse of power he thinks he could use to get them to shut up and stop hating him.