Element API, VueJs and Imager!
So the problem is that you're using an example from my older article, which was written for Craft 2.x. This line:

craft()-&gt;config-&gt;set('generateTransformsBeforePageLoad', true);


...and also these lines:

if (craft()-&gt;plugins-&gt;getPlugin('Imager')) {
    $image = craft()-&gt;imager-&gt;transformImage($srcImage, [


...are specific to Craft 2.x; anything craft() is Craft 2.x; you can see some of the changes here: https://docs.craftcms.com/v3/extend/updating-plugins.html#high-level-notes