Different mobile and desktop layout with vuejs

Viewed 13826

I'm looking a lightweight and smart way to provide user with different layout or component for mobile and desktop view using vue.

My web application consist of a lot of table and as you all know table is not a best experience when use in mobile device (even thought there is a lot of method to make table useable but not enjoyable)

So i thinking to make vue js to detect whether user access web apps from desktop or mobile device. when user open in desktop it will showing a good old table because of screen real estate desktop user have. But when user open in mobile device it will show card or panel like view that more suitable for mobile device (portrait orientation in general)

I know there is a solution with great bootstrap frameworks that can do that, but it is not swapping but instead render all part (html for most part) and just hide each part according to the screen size.

But maybe there is a much more efficient and smart way to implement these features in vue js?

2 Answers

I would say that you should consider css to handle the layout differences, but my view on this is that the way users interact with the content/app/etc can be significantly different between mobile and pc/laptop, beyond just sizing and placing divs differently. If you're providing a different-enough experience based on device, then handling the difference in your js may work better for you.

you can use a library like http://detectmobilebrowsers.com/ to determine if user is using mobile. Then store that val (isMobile) in a globally accessible variable, using vuex, bus or mixin. This will allow you to create mobile versions of your components that you can code-split, and have separate css files. Which I think will make the application easier to maintain long-term (IMHO, but this depends on some factors).

Related