Dynamic Layout with a useLayout Composable
Learn how to manage dynamic layouts using uselayout composable.
We'll cover the following...
Manage layout using Composition API
Composition API is another way in which we can manage layouts. We’ll create a useLayout composable that works in a similar way to the pageLayoutService, but the code will be much more succinct, as we’ll see in a moment. Due to how the Composition API works, we won’t need the layoutComputed. Instead, we only need to define a reactive value with the ref and provide the useLayout function.
As in the previous example, we also have to update the Layout and LayoutExample components.
In the LayoutExample component, we update the script like this:
The updated script for the Layout component is:
As mentioned before, the useLayout.js requires less code than the layoutService, and consuming its values and methods is much cleaner, as we don’t have to spread layoutComputed, nor assign LAYOUTS on the instance in the created hook. We initialize ...