I am developing an SPA using Vue 2.0. The components developed so far are for the "desktop" browsers, for example, I have
Main.vue, ProductList.vue, ProductDetail.vue,
I want another set of components for the mobile browsers, such as MainMobile.vue, ProductListMobile.vue, ProductDetailMobile.vue,
My question is, where and how do I make my SPA render the mobile version of components when viewing in a mobile browser?
Please note that I explicitly want to avoid making my components responsive. I want to keep two separate versions of them.
Thanks,
You need to bind the value into the component and then emit a new value to the parent when you click a link. If you emit the event input and bind the value value , then you can use v-model .
There are only three different ways to share data across the VueJs components, it depends on you which technique is better for you to solve your problem. Using props share data from parent to child. Using Event Emitting custom events to share data from child to parent.
Vue Native is a JavaScript framework designed to help you build cross-platform mobile applications with JavaScript. Vue Native is a wrapper around React Native that enables you to build mobile applications using Vue. js.
Open in browser To view the project, open a tab and type http://localhost:3000 into the URL bar. That's the address that the Node server is listening to. You should now see this page, which is the basic structure of our project.
I have simple solution for Vue.js:
<div v-if="!isMobile()"> <desktop> </desktop> </div> <div v-else> <mobile> </mobile> </div>
And methods:
methods: { isMobile() { if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { return true } else { return false } } }
I have an idea, use a [mixin][1] which detects if the browser is opened on mobile or desktop (example for js code in this [answer][2] ).. then use v-if, for example
<production-list v-if="!isMobile()"></production-list> <production-list-mobile v-else></production-list-mobile>
so here is an example on https://jsfiddle.net/Ldku0xec/ [1]: https://vuejs.org/v2/guide/mixins.html [2]: Detecting a mobile browser
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With