[英]Is there any better way or importing mixins in vue.js
I have many mixins created in my project and right now what i do is i will import all the mixins in mixins/index.js
files and in any components or pages wherever required i'll just import those mixins from mixins/index.js
.我在我的项目中创建了许多 mixin,现在我要做的是导入
mixins/index.js
文件和任何需要的组件或页面中的所有 mixins,我只需从mixins/index.js
导入这些 mixins。
Now i doubt if doing show will i import all the unwanted mixins as well or will just import the mixins files i use?现在我怀疑是否进行 show 我会导入所有不需要的 mixin 还是只导入我使用的 mixins 文件?
Let's say i have these mixims created and imported in mixins/index.js
假设我在
mixins/index.js
创建并导入了这些 mixim
import a from 'mixins/a.js'
import b from 'mixins/b.js'
import c from 'mixins/c.js'
import d from 'mixins/d.js'
import e from 'mixins/e.js'
export {
a,
b,
c,
d,
e
}
Now lets say in my 'x' components
i will import 'a' mixins
.现在让我们说在我的
'x' components
我将导入'a' mixins
。
import { a } from 'mixins/index.js'
export default {
mixins: [a]
}
In this case i only need 'a' mixins
in my 'x' components
but since i'm importing from mixins/index.js
where i have all static imports of all mixins will this load unwanted mixins as well?在这种情况下,我只需要在我的
'x' components
'a' mixins
,但由于我是从mixins/index.js
导入的,在那里我拥有所有 mixin 的所有静态导入,这是否也会加载不需要的 mixin?
You con do something like this, import all the minmins files and than export your minmin files in the index, like this:你做这样的事情,导入所有的 minmins 文件,然后在索引中导出你的 minmin 文件,如下所示:
index.js索引.js
import a from '../mixins/a.js'
import b from '../mixins/b.js'
import c from '../mixins/c.js'
import d from '../mixins/d.js'
import e from '../mixins/e.js'
export {a, b, c, d, e}
then in your component, you can import a specific module exported in the index in this way:然后在您的组件中,您可以通过这种方式导入索引中导出的特定模块:
x component x分量
import {a, b} from "../mixins"
in this way you import only what you need and not all the index.js
modules这样你只导入你需要的东西而不是所有的
index.js
模块
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.