Using pages and data
-
Hi
I built an app with several tabs in index.vue. My codebase has become quite bloated and not easy to navigate through. I would like to use pages and have a file (e.g. page1.vue) for each of these tabs. So index.vue would consist of data, methods, tabs and pages routes.
Since each page would contain the following<template> ... html code ... </template> <script> data () { }, methods: { } </script>
What should I do to get the data in all the pages and have it all in one place in index.vue? Is it something similar to components?
thanks
-
Use Vuex. Read Vuex docs first, then head to Quasar docs: https://quasar-framework.org/guide/app-vuex-store.html
Also additional read:
- https://quasar-framework.org/guide/app-adding-pages-and-layouts.html
- https://quasar-framework.org/guide/app-routing.html
Make sure you understand how Vue Router works before diving in.
-
Thanks @rstoenescu. Is Vuex the only option available?
-
No. You could build a similar store with a JS object that you import where you need it, but I don’t recommend it unless you really know how Vue works.
Don’t be scared of Vuex though. -
technically you could also make a so-called global mixin and integrate it as a plugin via the standard quasar.conf.js approach, but I highly recommend VUEX too.