【问题标题】:startActivity is undefined when running Nativescript-Vue app not via Playground未通过 Playground 运行 Nativescript-Vue 应用程序时未定义 startActivity
【发布时间】:2018-06-25 14:07:35
【问题描述】:

我创建了一个非常小的应用程序,对于 Android,它会在加载第一页时显示进入沉浸式模式。我遇到的问题是 app.android.startActivity 未定义,因此我无法让装饰窗口更改系统 UI 可见性。如果我通过 Chrome 的 Devtools 进行检查,我可以轻松访问 StartActivity,当我在 Playground 中尝试相同的代码时,它可以完美运行。

<template>
 <Page
  class="page page__start"
  actionBarHidden="true"
  backgroundSpanUnderStatusBar="true"
  @loaded="pageLoaded"
>
 <StackLayout>
   <FlexboxLayout flexDirection="column">
   </FlexboxLayout>
 </StackLayout>
 </Page>
</template>

<script>
 export default {
 methods: {
  pageLoaded: (args) => {
    const app = require('application');
    const platform = require('platform');
    const View = android.view.View;

    if (app.android && platform.device.sdkVersion >= '21') {
      const window = app.startActivity.getWindow();
      const decorView = window.getDecorView();
      decorView.setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_FULLSCREEN
        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }
  }
 }
};

更新:这是package.json,我不认为这是一个依赖问题,因为应用程序和平台不应该是依赖关系。

"dependencies": {
  "@teammaestro/nativescript-svg": "^1.0.1",
  "ajv": "^6.5.1",
  "nativescript-theme-core": "^1.0.4",
  "nativescript-vue": "^1.3.1",
  "tns-core-modules": "~3.4.1",
  "vue-router": "^3.0.1",
  "vuex": "^3.0.1"
},
"devDependencies": {
  "babel-core": "^6.26.0",
  "babel-loader": "^7.1.4",
  "babel-plugin-transform-object-rest-spread": "^6.26.0",
  "babel-preset-env": "^1.6.1",
  "copy-webpack-plugin": "^4.5.1",
  "css-loader": "^0.28.11",
  "extract-text-webpack-plugin": "^3.0.2",
  "fs-extra": "^5.0.0",
  "nativescript-vue-externals": "^0.2.0",
  "nativescript-vue-loader": "^0.1.5",
  "nativescript-vue-target": "^0.1.0",
  "nativescript-vue-template-compiler": "^1.3.1",
  "node-sass": "^4.7.2",
  "ns-vue-loader": "^0.1.2",
  "optimize-css-assets-webpack-plugin": "^3.2.0",
  "rimraf": "^2.6.2",
  "sass-loader": "^6.0.7",
  "vue-template-compiler": "^2.5.16",
  "webpack": "^3.11.0",
  "webpack-synchronizable-shell-plugin": "0.0.7",
  "winston-color": "^1.0.0"
}

这里是工作游乐场的链接:https://play.nativescript.org/?template=play-vue&id=m1qdiD

【问题讨论】:

  • 你成功了吗?

标签: android vue.js nativescript


【解决方案1】:

如果它在操场上工作。这可能是一个依赖问题。您是否使用 npm 安装了所有插件?如果您可以从 package.json 添加依赖版本,那就太好了。这里可能有一个潜在的错误: const app = require('application'); const platform = require('platform'); 另外,检查您是否有标签。我建议分享您的 NativeScript-Vue 游乐场 URL。

【讨论】:

  • 更新了原帖。
【解决方案2】:

我遇到了同样的问题,只需从app.android.startActivityapp.startActivity 调用startActivity 就可以了。

【讨论】:

    猜你喜欢
    • 2019-04-07
    • 2020-02-28
    • 2020-03-07
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2019-03-24
    • 2020-11-27
    • 1970-01-01
    相关资源
    最近更新 更多