gpt4 book ai didi

javascript - Vuejs 路由器无法访问任何组件

转载 作者:行者123 更新时间:2023-11-30 14:48:43 25 4
gpt4 key购买 nike

我可能使用了一些过时的指南,这可能是它的结果,对 Vuejs 来说是新的。
我的 App.vue:

<template>
<div id="app">
<img src="../assets/logo.png">
<router-view/>
</div>
</template>

<script>
export default {
name: 'App'
}
</script>

<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>

我的ma​​in.js:

import Vue from 'vue'
import { App } from './app'
import router from './router'
import store from './store'

/* eslint-disable no-new */
new Vue({
el: '#app',
store,
router,
template: '<App/>',
components: { App }
})

router/index.js

import Vue from 'vue'
import Router from 'vue-router'
import { routes } from '../app'

Vue.use(Router)

export default new Router({
mode: 'history',
routes: routes
})

然后是 app/routes.js

import accounts from './accounts'
import budgets from './budgets'
import transactions from './transactions'

export default [...accounts, ...budgets, ...transactions]

最后,app/accounts/routes.js

import * as components from './components'

export default [
{
path: '/',
component: components.AccountsListView,
name: 'accountsListView'
},
{
path: '/accounts/create',
component: components.CreateEditAccounts,
name: 'createAccounts'
},
{
path: '/accounts/edit',
component: componenets.CreateEditAccounts,
name: 'editAccounts'
}
]

出于某种原因,我无法点击我的任何组件,例如,如果我转到 localhost:8080/accounts/create,那么我最终会进入具有更改后的 url 的索引页面,而不是点击相应的组件。我正在做的事情有什么明显的错误吗?

最佳答案

对于这次导出

export default [
{
path: '/',
component: components.AccountsListView,
name: 'accountsListView'
},
{
path: '/accounts/create',
component: components.CreateEditAccounts,
name: 'createAccounts'
},
{
path: '/accounts/edit',
component: componenets.CreateEditAccounts,
name: 'editAccounts'
}
]

由于路由数组是默认导出,因此您需要使用此导入。
对象样式导入适用于存在多个导出的情况。

import routes from '../app'

引用:MDN web docs - export

关于javascript - Vuejs 路由器无法访问任何组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48493996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com