Vue-Nativescript Back-Navigation 使 iOS 应用程序崩溃

Posted

技术标签:

【中文标题】Vue-Nativescript Back-Navigation 使 iOS 应用程序崩溃【英文标题】:Vue-Nativescript Back-Navigation crashes iOS App 【发布时间】:2021-04-24 21:36:47 【问题描述】:

一旦我返回主站点,我就无法正确导航并遇到崩溃。这发生在我的 ios 设备和虚拟设备上。

我的结构如下:

我的 package.json 中的依赖项:

"dependencies": 
    "@nativescript/core": "7.1.3",
    "@nativescript/theme": "3.0.1",
    "@nstudio/nativescript-cardview": "2.0.1",
    "axios": "^0.19.2",
    "js-cookie": "^2.2.1",
    "kinvey-nativescript-sdk": "6.0.0",
    "moment": "^2.24.0",
    "nativescript-background-http": "4.2.1",
    "nativescript-camera": "4.5.0",
    "nativescript-fonticon": "^2.0.0",
    "nativescript-http-formdata": "^2.1.0",
    "nativescript-image": "3.0.1",
    "nativescript-imagepicker": "7.1.0",
    "nativescript-intl": "3.0.0",
    "nativescript-iqkeyboardmanager": "1.5.1",
    "nativescript-theme-core": "2.0.24",
    "nativescript-ui-autocomplete": "7.0.2",
    "nativescript-ui-calendar": "6.1.0",
    "nativescript-ui-chart": "7.1.1",
    "nativescript-ui-dataform": "7.0.4",
    "nativescript-ui-gauge": "6.0.0",
    "nativescript-ui-listview": "8.0.1",
    "nativescript-ui-sidedrawer": "8.0.0",
    "nativescript-vue": "2.8.3",
    "terser-webpack-plugin": "^2.3.5",
    "vform": "^1.0.1",
    "vue-i18n": "^8.17.0",
    "vuex": "^3.1.3"
  

app.js

    new Vue(
      store,
      render: h => h('frame', [h(routes.login)]),
      created() 
      ,
    ).$start();

登录成功后,我会被重定向到Main.vue。

Main.vue 包含以下内容(底部导航和包含的主菜单组件 -> 主页):

    <template>
      <Page actionBarHidden="true">
        <ActionBar title="App-Name"></ActionBar>
        <StackLayout>
          <StackLayout>
              
            <BottomNavigation >
              <TabStrip>
                <TabStripItem>
                  <Label text="Home"></Label>
                  <Image src="res://home"></Image>
                </TabStripItem>
                <TabStripItem>
                  <Label text="Einstellungen"></Label>
                  <Image src="res://settings"></Image>
                </TabStripItem>
                <TabStripItem>
                  <Label text="Info"></Label>
                  <Image src="res://browse"></Image>
                </TabStripItem>
              </TabStrip>
              <TabContentItem>
                <GridLayout>
                  <Home></Home>
                </GridLayout>
              </TabContentItem>
              <TabContentItem>
                <GridLayout>
                  <Settings></Settings>
                </GridLayout>
              </TabContentItem>
              <TabContentItem>
                <GridLayout>
                  <Info></Info>
                </GridLayout>
              </TabContentItem>
            </BottomNavigation>
          </StackLayout>
        </StackLayout>
      </Page>
    </template>

包含主菜单的 Home 组件如下所示:

&lt;template&gt; &lt;/template&gt; 并包含具有@tap 功能的卡片以转到下一页。

    methods: 
        logout() 
          this.$store.dispatch("clearUser");
        ,
        goToPageXY() 
          this.$navigateTo(PageXY, 
            clearHistory: false,
          );
        ,
      ,

通过点击调用的页面(在这种情况下为 PageXY)包含以下结构:

<template>
  <Page class="page">
</Page>
</template>

“更深”页面中的进一步导航按预期工作,我可以根据需要使用“返回”按钮。

问题: 一旦我想导航回 Main.vue(从 PageXY 通过历史模式 ON 或 $navigateTo / $navigateBack 返回),应用程序就会崩溃。这只发生在该页面上。

错误输出如下:

    ***** Fatal javascript exception - application has been terminated. *****
    Native stack trace:
    1   0x10de4b62e NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState*, JSC::Exception*, bool)
    2   0x10de8c3a8 NativeScript::FFICallback<NativeScript::ObjCMethodCallback>::ffiClosureCallback(ffi_cif*, void*, void**, void*)
    3   0x10e887c90 ffi_closure_unix64_inner
    4   0x10e8886b2 ffi_closure_unix64
    5   0x7fff23f47ce3 -[UIViewController __viewDidAppear:]
    6   0x7fff23f47fbc -[UIViewController _endAppearanceTransition:]
    7   0x7fff23e6d6a3 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
    8   0x7fff23e62284 __49-[UINavigationController _startCustomTransition:]_block_invoke
    9   0x7fff23f6c4b8 -[_UIViewControllerTransitionContext completeTransition:]
    10  0x7fff23f83680 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke.155
    11  0x7fff24bcb250 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:]
    12  0x7fff24b9bb62 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
    13  0x7fff24b9c101 -[UIViewAnimationState animationDidStop:finished:]
    14  0x7fff24b9c285 -[UIViewAnimationState animationDidStop:finished:]
    15  0x7fff27a8a4f6 CA::Layer::run_animation_callbacks(void*)
    16  0x7fff20106508 _dispatch_client_callout
    17  0x7fff20112ff7 _dispatch_main_queue_callback_4CF
    18  0x7fff2038bdab __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
    19  0x7fff2038662e __CFRunLoopRun
    20  0x7fff203856c6 CFRunLoopRunSpecific
    21  0x7fff2b76adb3 GSEventRunModal
    22  0x7fff24675187 -[UIApplication _run]
    23  0x7fff2467a038 UIApplicationMain
    24  0x10e8884f5 ffi_call_unix64
    25  0x115a85090
    JavaScript stack trace:
    file: node_modules/nativescript-vue/dist/index.js:4880:17
    at destroy(file: node_modules/nativescript-vue/dist/index.js:4046:8)
    at invokeDestroyHook(file: node_modules/nativescript-vue/dist/index.js:5455:60)
    at patch(file: node_modules/nativescript-vue/dist/index.js:5808:47)
    at file: node_modules/nativescript-vue/dist/index.js:4886:17
    at handler(file: node_modules/nativescript-vue/dist/index.js:12773:12)
    at _handleEvent(file: app/packages/core/data/observable/index.ts:296:19)
    at notify(file: app/packages/core/data/observable/index.ts:278:27)
    at onNavigatedFrom(file: app/packages/core/ui/page/page-common.ts:139:14)
    at raiseCurrentPageNavigatedEvents(file: app/packages/core/ui/frame/frame-common.ts:310:24)
    at _updateBackstack(file: app/packages/core/ui/frame/frame-common.ts:268:39)
    at setCurrent(file: app/packages/core/ui/frame/index.ios.ts:58:25)
    at file:///app/vendor.js:39242:23
    at UIApplicationMain([native code])
    at run(file: app/packages/core/application/index.ios.ts:395:20)
    at file: node_modules/nativescript-vue/dist/index.js:12548:23
    at file:///app/bundle.js:6582:10
    at ./app.js(file:///app/bundle.js:6586:34)
    at __webpack_require__(file: app/webpack/bootstrap:750:0)
    at checkDeferredModules(file: app/webpack/bootstrap:43:0)
    at webpackJsonpCallback(file: app/webpack/bootstrap:30:0)
    at anonymous(file:///app/bundle.js:2:61)
    at evaluate([native code])
    at moduleEv<…>
    JavaScript error:
    file: node_modules/nativescript-vue/dist/index.js:4880:17: JS ERROR TypeError: undefined is not an object (evaluating 'vm._data.__ob__')
    ***** Fatal JavaScript exception - application has been terminated. *****

我的感觉告诉我,我在使用页面/框架时犯了错误。

我非常感谢任何形式的帮助,因为我已经为此苦苦挣扎了好几个小时。 非常感谢!

【问题讨论】:

【参考方案1】:

如果您使用的是框架 试试这个

this.$navigateTo(PageXY, 
     frame: 'frame',
);

要回去试试这个:

this.$navigateBack(frame: "frame");

【讨论】:

以上是关于Vue-Nativescript Back-Navigation 使 iOS 应用程序崩溃的主要内容,如果未能解决你的问题,请参考以下文章