【问题标题】:[Vue warn]: Cannot find element: #app Express[Vue 警告]:找不到元素:#app Express
【发布时间】:2018-08-10 12:20:29
【问题描述】:

在新项目中,我的应用在 expressJs 服务器上找不到带有 VueJS (2.5.13) 的根元素。

我的 index.html:

<html>
    <head>
        <title>Test</title>
    </head>
    <body>
        <div id="app"></div>
        <script src="dist/index.js"></script>
    </body>
</html>

我的 js 入口点:

import Vue from 'vue'
import App from './App'

new Vue({
   render: h => h(App)
}).$mount('#app')

还有我非常基础的 App.vue:

<template>
    <div>
        Hello the world
    </div>
</template>
<script>
    export default {
        name: 'app'
    }
</script>
<style>
</style>

我使用 babel-loader 和 webpack。我不明白为什么 Vue 找不到 #appid。

感谢您的帮助

【问题讨论】:

  • 为什么不new Vue({ el: '#app', render: h =&gt; h(App) })

标签: express webpack vuejs2 babel-loader


【解决方案1】:
 <template>
   <div id="app"> <----- id="app"
     Hello the world
   </div>
 </template>

尝试将 id="app" 添加到 App.vue 中的 div 中

new Vue({
  el: '#app', <-------- el: '#app'
  render: h => h(App)
})

【讨论】:

    猜你喜欢
    • 2017-05-15
    • 2018-01-04
    • 2015-06-11
    • 2018-04-28
    • 2019-05-16
    • 2021-11-19
    • 2017-08-20
    • 2018-02-06
    • 2017-12-22
    相关资源
    最近更新 更多