构建vue路由:
这个foreach报错,意味着有一个进入循环的值为null。如果看了其他文章的标准还没有解决的话,建议加一个routes:constantRoutes,即在定义router时手动加上一个routes属性。
完整的代码:
App.vue

<template>
    <div id="app">
        <router-view/>
    </div>
</template>

<script>

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

main.js

import  { createApp }  from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router/index'

const app = createApp(App)
app.use(ElementPlus,{ size: 'small', zIndex: 3000 })
app.use(router)
app.mount('#app')

router/index.js


import { createRouter, createWebHistory } from 'vue-router'
import PersonInfo from '../components/PersonInfo'

const routerHistory = createWebHistory()

const constantRoutes = [
    {
        path: '/login',
        component: PersonInfo
    }
]


let router = createRouter({
    history: routerHistory,
    routes:constantRoutes,
})

export default router;

Logo

前往低代码交流专区

更多推荐