0

I am currently trying to build my first webapp using vue.js

Now 2 days of tutorials deep I am still not 100% sure how to structure a basic application. Using the vue-cli and webpack already makes a nice structure, including a /src Folder with components and a /router Folder for routing.

Now my plan is to create a ToDo App. I want to dynamically switch between [show todos] and [add todo], which is just a form with a submit button. I have already achieved it by using it without components and the cli.

My structure would be:

App.vue -> buttons with the two router-link to components/ShowTodos.vue & components/AddTodos.vue

components/ShowTodos.vue -> Table including the todo list

components/AddTodos.vue -> Form with submit button

Now the routing part works, I am able to switch between those two components.

Now 2 Questions:

  1. How can I push the information from the form in the AddTodos component into an Array in the ShowTodos component in order to loop through there ?

  2. Is this a proper way to structure an vue app, and if not how can I improve it ?

    Thank you very much.

This is the first time for me using a component based JS Framework, so its pretty hard to follow along.

enter image description here

3 Answers 3

1

On structuring your vuejs application , this can be helpful

app/
   moduleA/
      components/
      index.js
      routes.js
   moduleB/
      components/
      index.js
      routes.js
   index.js
   routers.js
   main.vue
   router/
   components/ -> shared
   main.js

// app/routes.js
import { routes as moduleA } from './moduleA'
import { routes as moduleB } from './moduleB'
export default [ ...moduleA, ...moduleB ]

// app/moduleA/index.js
export { default as routes } from './routes'

// app/moduleB/index.js
export { default as routes } from './routes'

// app/index.js
export { default as routes } from './routes

'

Sign up to request clarification or add additional context in comments.

Comments

1

About the second question, I did some researches, and that's what I recommend:

.
├── app.css
├── App.vue
├── assets
│   └── ...
├── components
│   └── ...
├── main.js
├── mixins
│   └── ...
├── router
│   └── index.js
├── store
│   ├── index.js
│   ├── modules
│   │   └── ...
│   └── mutation-types.js
├── translations
│   └── index.js
├── utils
│   └── ...
└── views
    └── ...

Read more here: https://medium.com/@sandoche/how-to-structure-a-vue-js-project-eabe75161882

Comments

0

I can recommend this boilerplate. It has a very good structure and I am now using it in every project.

/components
/layouts
/mixins
/pages
/routes
/services
/store
/transformers

He also explains the structure very well. https://github.com/petervmeijgaard/vue-2.0-boilerplate#structure

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.