【问题标题】:Nativescript-Vue: 'tns preview' error with loading Vuex?Nativescript-Vue:加载 Vuex 时出现“tns 预览”错误?
【发布时间】:2020-05-19 14:43:56
【问题描述】:

对于我正在为移动设备开发的琐事应用程序,我正在使用 Nativescript-Vue 进行开发。该应用程序在使用 xcode iOS 模拟器运行时运行良好且没有错误。但是,当我尝试运行预览(使用终端命令:'tns preview')时,应用会运行,但是当我尝试启动游戏时,应用会抛出错误:

CONSOLE ERROR file:///app/tns_modules/nativescript-vue/dist/index.js:2129:20: [Vue warn]: Error in render: "TypeError: undefined is not an object (evaluating 'this.$store.getters')"

found in

---> <App> at App.vue
       <Frame>
        <Root>
LOG from device iPhone CONSOLE ERROR file:///app/tns_modules/nativescript-vue/dist/index.js:2129:20: [Vue warn]: Error in nextTick: "TypeError: undefined is not an object (evaluating 'this.$store.getters')"

我正在尝试使用 iPhone SE 上的 Playground 应用程序运行它并扫描二维码。我认为这与应用程序无法访问 VueX 商店或其他原因有关。但我有点不知所措。我已经看到“tns preview”命令起作用了,但那是在没有 Vuex 的 Vue 应用程序中使用的。你知道我做错了什么吗?

更新:在 main.js 中添加 Vue.prototype.$store = store 后,我得到一个稍微不同的错误:

CONSOLE ERROR file:///app/tns_modules/nativescript-vue/dist/index.js:2129:20: [Vue warn]: Error in render: "TypeError: this.$store.getters is not an Object. (evaluating 'val in this.$store.getters')"

仍然不知道可能出了什么问题,但我确实知道 tns 预览在禁用/注释掉代码中与商店相关的所有内容时有效,因此它肯定与此有关。请帮忙,我真的很想通过手机向某人展示这个应用程序。

【问题讨论】:

  • this.$store.getters 应该是您商店中的一个状态。您能出示您的商店定义代码吗?
  • 嘿,感谢您的回复,但我在发布此问题几天后决定切换到 Vue Native 而不是 NativeScript 并为此重写我的应用程序,因为总的来说它显示的错误行为要少得多在尝试在手机设备上预览时,也关于 VueX。至少对我来说,可能是因为我更熟悉 Expo 应用程序而不是 NativeScript。无论如何,它现在工作得更顺畅了。
  • 有没有其他人遇到过这个问题,我真的希望在这里得到答案?
  • 我的建议是使用 Vue Native 而不是 NativeScript-Vue。就 VueX 而言,它似乎工作得更好,并且能够在手机上快速预览仍在开发中的应用程序。此外,它基本上仍然以与 NativeScript 相同的方式工作,因此转换您已有的内容并不需要很长时间。

标签: vue.js vuex nativescript-vue tns


【解决方案1】:

我已经设法通过在导入商店后添加main.js 这一行来解决这个问题:

import store from './store'
Vue.prototype.$store = store

【讨论】:

    猜你喜欢
    • 2020-12-04
    • 2019-04-19
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-10
    • 2019-10-15
    • 1970-01-01
    相关资源
    最近更新 更多