【发布时间】:2018-04-26 07:53:00
【问题描述】:
我关注this blog。按描述添加代码后,window.app 属性确实出现在控制台中,但是我无法引用博客中提到的app.$store ans(这类似于在组件中引用商店的方式)。我可以引用app.store,它确实包含我的vuex 存储中的属性,但它不包含app.store.state,只是getter(和调度等)。
例如使用const getStore = () => cy.window().its('app.store') 它给出:
我希望能够直接使用状态变量,而不仅仅是在我为它创建一个 getter 时。怎么了?这是因为我在我的 vuex 商店中使用了命名空间吗?
编辑:
这也可能与我将商店分配到窗口的方式有关。我使用 Quasar Framework,在当前版本 (>0.15) 中,它根据它使用的 quasar.conf.js 文件中的设置进行了大量配置。我通过将此代码添加为quasar plugin 来分配商店:
export default ({ app, store, Vue }) => {
if (window.Cypress) { // should only be available during E2E tests
window.app = app
}
}
这样做确实给了我我提到的app.store,但不是app.$store(包括state)。 Quasar 配置生成并显示在一个文件中,添加此插件后该文件包含:
/**
* THIS FILE IS GENERATED AUTOMATICALLY.
* DO NOT EDIT.
*
* You are probably looking on adding initialization code.
* Use "quasar new plugin <name>" and add it there.
* One plugin per concern. Then reference the file(s) in quasar.conf.js > plugins:
* plugins: ['file', ...] // do not add ".js" extension to it.
**/
import './quasar'
import Vue from 'vue'
Vue.config.productionTip = false
import 'quasar-app-styl'
import 'src/css/app.styl'
import App from 'src/App'
import router from 'src/router'
import store from 'src/store'
const app = {
el: '#q-app',
router,
store,
...App
}
const plugins = []
import pluginCypress_vuex_store from 'src/plugins/cypress_vuex_store'
plugins.push(pluginCypress_vuex_store)
import pluginVuelidate from 'src/plugins/vuelidate'
plugins.push(pluginVuelidate)
plugins.forEach(plugin => plugin({ app, router, store, Vue }))
new Vue(app)
正如您所见,插件是初始化 Vue 应用程序的一部分,而博客和您建议的方式是在 Vue 初始化之后附加的。由于 Quasar 自动生成配置,我不知道如何在初始化后执行“window.app = app”,看看这是否会导致我的问题......
【问题讨论】:
标签: javascript vue.js vuex cypress quasar-framework