[英]How to access app.vue methods from es6-module?
I am building a vuejs app with webpack, vuex and vue-router.我正在使用 webpack、vuex 和 vue-router 构建一个 vuejs 应用程序。
My Project structure looks like this:我的项目结构如下所示:
[components] [成分]
[store] [店铺]
[restapi] [restapi]
App.vue应用程序
main.js主文件
I'm using BlockingLayer.vue inside of App.vue.我在 App.vue 中使用 BlockingLayer.vue。 App.vue has methods to show/hide BlockingLayer.
App.vue 有显示/隐藏 BlockingLayer 的方法。
Now I want to be able to trigger those methods from the [restapi] index.js - how do I do that?现在我希望能够从 [restapi] index.js 触发这些方法 - 我该怎么做?
I tried importing App.vue inside my restapi module - doesn't work.我尝试在我的 restapi 模块中导入 App.vue - 不起作用。 Meanwhile importing store inside restapi works flawlessly.
同时,在 restapi 中导入 store 可以完美运行。 Importing restapi inside store and using it there also works just fine.
在商店内导入 restapi 并在那里使用它也可以正常工作。 What I could do is using a variable inside the store instead of inside App.vue to show/hide the BlockingLayer I guess, but that's not really what store is meant to be used for I would say...
我能做的是使用商店内的变量而不是 App.vue 内的变量来显示/隐藏我猜的 BlockingLayer,但这并不是我想说的真正用于商店的东西......
I'm using vuex to store the state of BlockingLayer and vuex actions to show/hide it instead of having the state stored in App.vue now.我正在使用 vuex 来存储 BlockingLayer 的状态,并使用 vuex 操作来显示/隐藏它,而不是现在将状态存储在 App.vue 中。 Works like a charm.
奇迹般有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.