在我的Vuejs项目中,我有一些常见的js函数,可以通过多个组件使用:
我的代码 struct 如下,它是在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>
在本例中,我想创建一个函数loginRequired
,它将在几个组件中调用.
那么我应该如何组织代码呢