In my Vuejs project, I have some common js functions which would be used through multiple components:
My code structure is as below, which was introduced in http://vuejs.github.io/vuex/en/structure.html:
├── index.html
├── main.js
├── components
│ ├── App.vue
│ └── ...
└── vuex
├── store.js # exports the store (with initial state and mutations)
└── actions.js # exports all actions
some_component.vue
<template>
// The page content
</template>
<script>
export default {
attached: function() {
if(!isLoggedIn) {
$this.router.go('/signin');
}
}
}
</script>
In this case, I want to make a function loginRequired
which would be called in several components.
So how should I organize the code?