某些组件无法注入到App.vue模板中。特别是Login.vue
是引起问题的那个。如果我在服务器运行(npm run dev
)时从头开始创建它,它将起作用,但是一旦重新启动并导航到Login组件,它将无法加载。
堆栈跟踪
[Vue warn]: Failed to mount component: template or render function not defined.
found in
---> <Login>
<App> at src/App.vue
<Root>
src / components / Login.vue
<template>
<div id="login">
<ul>
<li><input type="text" v-model="username" placeholder="Username"></li>
<li><input type="password" v-model="password" placeholder="Password"></li>
<li><button @click="login(username, password)">Login</button></li>
</ul>
</div>
</template>
<script>
</script>
<style scoped>
#login{
padding-top: 100px;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
</style>
src / router / index.js
import Vue from 'vue'
import Router from 'vue-router'
import Hello from '@/components/Hello'
import RideSharing from '@/components/RideSharing'
import Login from '@/components/Login'
import About from '@/components/About'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'Hello',
component: Hello
},
{
path: '/app',
name: 'RideSharing',
component: RideSharing
},
{
path: '/app/login',
name: 'Login',
component: Login
},
{
path: '/app/about',
name: 'About',
component: About
}
]
})
src / App.vue
<template>
<div id="app" :style="{padding: $route.path === '/' ? '172px' : '10px'}">
<div>
<img src="./assets/logo4.png" align="center">
</div>
<router-view></router-view>
</div>
</template>
<script>
export default {
name: 'app'
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
background-color: hsla(269, 96%, 50%, 0.73);
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 0px;
height: inherit;
}
body{
height: inherit;
}
html{
height: 100%;
}
</style>
src / main.js
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import BootstrapVue from "bootstrap-vue"
import App from './App'
import router from './router'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
Vue.use(BootstrapVue)
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App }
})
答案 0 :(得分:0)
如果您使用的是Vue的完整版,则可以尝试使用.$mount('#app')
因此,在main.js中,您的应用程序脚本应如下所示:
new Vue({
router,
template: '<App/>',
components: { App },
}).$mount('#app')
答案 1 :(得分:0)
解决方案:
在导入中缺少.vue
个扩展名。
src / router / index.js
import Vue from 'vue'
import Router from 'vue-router'
import Hello from '@/components/Hello.vue'
import RideSharing from '@/components/RideSharing.vue'
import Login from '@/components/Login.vue'
import About from '@/components/About.vue'