Currently, I am working on developing a form creation feature that allows users to select a background color for their forms. This selection would then reflect as the background color of the body tag. Users are given several color options to choose from, and their selection should automatically change the background color.
The project is being implemented using Laravel and Vue technologies. However, I am facing challenges in dynamically updating the background color based on user selections. I have explored different methods but haven't had much success so far.
One approach I tried was creating a beforeCreate hook to modify the body's background color:
beforeCreate() {
this.color = 'bc-header-red';
document.body.className = this.color;
},
Unfortunately, this method did not allow me to update the background color as desired, even with an update() hook. Another option I came across is similar to an implementation found in this jsfiddle link. Essentially, it involves binding the style of the body tag to a certain value. However, a challenge I faced here is that the body tag resides in my Laravel blade file rather than the Vue JS file. Is there a way to move it?
I am open to exploring other possible implementations or solutions to achieve the desired functionality. Any insights or suggestions would be greatly appreciated. Thank you!