分配为null时出现Typerror?

时间:2019-05-01 01:39:20

标签: vue.js nativescript vue-router

使用Nativescript-vue(〜2.0.0)并通过此tutorial集成vue-router(^ 3.0.6),我得到一个错误:

  

file:///app/bundle.js:876:7:JS错误TypeError:尝试分配   只读属性。 (CoreFoundation)***由于终止应用程序   未捕获的异常'NativeScript遇到致命错误:TypeError:   尝试分配给readonly属性。在1
  @file:///app/bundle.js:876:7 2
  ./router/index.js@file:///app/bundle.js:924:34 3
   webpack_require @file:///app/bundle.js:76:34 4 @file:///app/bundle.js:630:84 5
  ./app.js@file:///app/bundle.js:653:34 6
   webpack_require @file:///app/bundle.js:76:34 7 checkDeferredModules @ file:///app/bundle.js:45:42 8
  @file:///app/bundle.js:149:38 9
  匿名@文件:///app/bundle.js:150:12 10评估@ [本地代码] 11   moduleEvaluation @ [本机代码] 12 promiseReactionJob @ [本机代码] 13   require @ [本机代码] 14onymous @ file:///app/starter.js:2:8 15   评估@ [本机代码] 16模块评估@ [本机代码] 17   promiseReactionJob @ [本地代码]',原因:'(null)'

我有以下代码: app.js:

import Vue from "nativescript-vue";
import router from '~/router';

new Vue({
    router
}).$start();

使用此router / index.js:

import Vue from 'nativescript-vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

import Startup from '../components/Startup'
import OfficeHome from '../components/Office/OfficeHome'

const routes = [
  { path: '/home', component: Startup },
  { path: '/officeHome', component: OfficeHome },
  {path: '*', redirect: '/home'}
];

const router = new VueRouter({
  routes
});

router.replace('/home');
module.exports = router;

页面基本上是:

<template>
    <Page class="page">
        <ActionBar title="testing " class="action-bar" icon="" />

        <FlexboxLayout flexDirection="column" justifyContent="center" class="full-height">
            <!--Add your page content here-->
            <StackLayout class="container">
                <FlexboxLayout alignItems="center">
                    <Label textWrap="true" text="test tech"
                           class="intro-text" />
                </FlexboxLayout>
                <StackLayout>
                    <Button class="btn btn-primary" @tap="$router.push('/home')">Home</Button>
                    <Button class="btn btn-primary" @tap="$router.push('/officeHome')">Office</Button>
                </StackLayout>
            </StackLayout>
        </FlexboxLayout>
    </Page>
</template>

<script>
</script>

不确定是否会有所不同,但这是我的package.json:

{
  "nativescript": {
    "id": "com.company.me",
    "tns-android": {
      "version": "5.0.0"
    },
    "tns-ios": {
      "version": "5.0.0"
    }
  },
  "description": "NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "repository": "<fill-your-repository-here>",
  "dependencies": {
    "axios": "^0.18.0",
    "nativescript-dev-appconfig": "^1.0.2",
    "nativescript-nfc": "^3.0.1",
    "nativescript-theme-core": "~1.0.4",
    "nativescript-vue": "~2.0.0",
    "nativescript-vue-devtools": "^1.1.0",
    "node-uuid": "^1.4.8",
    "tns-core-modules": "~5.0.0",
    "vue-router": "^3.0.6",
    "vuex": "^3.0.1"
  },
  "devDependencies": {
    "@babel/core": "~7.1.0",
    "@babel/preset-env": "~7.1.0",
    "babel-loader": "~8.0.0",
    "nativescript-dev-webpack": "~0.17.0",
    "nativescript-vue-template-compiler": "~2.0.0",
    "node-sass": "~4.9.0",
    "vue-devtools": "^5.0.0-beta.1",
    "vue-loader": "~15.4.0",
    "webpack-synchronizable-shell-plugin": "0.0.7",
    "optimize-css-assets-webpack-plugin": "^3.2.0",
    "winston-color": "^1.0.0",
    "nativescript-vue-target": "^0.1.0",
    "nativescript-vue-externals": "^0.2.0"
  }
}

作为JS / NativeScript的新手,我不确定在哪里发生此错误。我认为该错误指示router / index.js,但没有第34行。

知道在哪里分配什么吗?

0 个答案:

没有答案