首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Vue -无法呈现组件

Vue -无法呈现组件
EN

Stack Overflow用户
提问于 2018-11-15 21:43:33
回答 2查看 1.1K关注 0票数 0

一些组件不能注入到App.vue模板中。特别是,导致问题的是Login.vue。如果我在服务器运行时从头开始创建它(npm run dev),它就会工作,但是一旦我重新启动它并导航到Login组件,它将无法加载。

堆栈跟踪

代码语言:javascript
复制
[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

代码语言:javascript
复制
<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

代码语言:javascript
复制
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

代码语言:javascript
复制
<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

代码语言:javascript
复制
// 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 }
})
EN

回答 2

Stack Overflow用户

发布于 2018-11-15 22:15:44

如果您正在使用Vue的完整构建版本,那么您可以尝试使用.$mount('#app')挂载DOM模板

因此,在您的main.js中,您的应用程序脚本应该如下所示:

代码语言:javascript
复制
new Vue({
  router,
  template: '<App/>',
  components: { App },
}).$mount('#app')
票数 0
EN

Stack Overflow用户

发布于 2018-11-16 01:14:41

解决方案:

导入中缺少.vue扩展。

src/router/index.js

代码语言:javascript
复制
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'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53328307

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档