How can widget.get_setting in main.js be accessed in frontend.js?

Hi,

For example, I’m returning an image url like this from main.js:

image

But I cannot return it from frontend.js:

Is it the cope of the ‘this’ keyword ? If yes, I’ve used ‘globalThis’…but also did not work.

Thanks,

Mark

Resolved by declaring variables for the images in main.js, then returning an array of the variables from main.js. The ‘this’ keyword then references the array in frontend.js (which it was not doing if the array was declared in data() in frontend.js).

Yes this looks correct, you shouldn’t need to do anything with data() at all in frontend.

Only data returned by get_template_data() in main.js will automatically become your reactive data in the Vue frontend, accessed via this.x

This does sometimes mean you may need to return object attributes with no value from get_template_data(), because you want those variable names to be usable later in the frontend code as reactive variables.

1 Like