Mar*_*tin 5 vue.js vuejs2 nuxt.js
我有一个 Nuxt 项目,我需要制作自定义函数和 Vue mixins 以在 Vue 组件和页面中重用。
In which folder should I put the files containing these? Should I create a 'lib' folder at the top level of the Nuxt project and put the files in there?
Extra details if that can help:
ham*_*kan 11
在我的 nuxt 项目中,我通常在项目的根目录级别添加四个文件夹,这些文件夹用于mixins
我的所有 mixins、models
我在整个应用程序中使用的模型或类,services
其中包含我的所有 API 端点以及utils
我的所有实用程序函数和其他通用函数,例如我的输入的验证函数和我的目录如下所示:
在这种情况下,mixins
您可以将所需的 mixin 导入到所需的组件中,并像平常一样使用它们:
import someMixin from '@/mixins/someMixin'
...
export default {
mixins: [someMixin],
...
}
Run Code Online (Sandbox Code Playgroud)