7
7
700Hp2021-08-30 19:56:37
Vue.js
700Hp, 2021-08-30 19:56:37

Not rendering vue component, why?

Console warning:

runtime-core.esm-bundler.js?5c40:6873 [Vue warn]: A plugin must either be a function or an object with an "install" function.
warn @ runtime-core.esm-bundler.js?5c40:6873
use @ runtime-core.esm-bundler.js?5c40:3415
eval @ main.js?56d7:6
./src/main.js @ app.js:1100
__webpack_require__ @ app.js:854
fn @ app.js:151
1 @ app.js:1149
__webpack_require__ @ app.js:854
checkDeferredModules @ app.js:46
(anonymous) @ app.js:994
(anonymous) @ app.js:997
runtime-core.esm-bundler.js?5c40:6873 [Vue warn]: Failed to resolve component: router-view 
  at <App app=null apps= [] options= {mode: "history", routes: Array(2)}  ... >


main.js file:
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'

const app = createApp(App, router)
app.use(router)
app.mount('#app')


router.js file:

import Router from 'vue-router'
import Home from './views/Home'
// import { VueElement } from 'vue'

const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      component: Home,
    },

    {
      path: '/todos',
      component: () => import('./views/Todos.vue'),
    },
  ],
})
export default router


Home page component Home.vue:

<template>
  <div>
    <h2>Home page</h2>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quod itaque
      tempore reiciendis.
    </p>

    <a href="/todos">Todos</a>
  </div>
</template>


Main App.vue file:
<template>
  <div id="app">
    <h1>Todo applictaion</h1>
    <hr />

    <router-view></router-view>
  </div>
</template>

<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>


So the app is working. It opens a page where it only displays the title and stroke from the App.vue file. How to fix?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2021-08-30
@delphinpro

A plugin must either be a function or an object with an "install" function

Now the translation tools are quite well developed, but let me translate:
The plugin must be a function, or an object containing the install () method.
In use, you need to put what you import from 'vue-router
'
import Router from 'vue-router'
Vue.use(Router)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question