【问题标题】:Problem with production mode (Rails 5.2.4.1 + VueJS + Webpack 3.12 + Heroku)生产模式问题(Rails 5.2.4.1 + VueJS + Webpack 3.12 + Heroku)
【发布时间】:2020-05-17 11:56:10
【问题描述】:

我的生产模式有问题。当我在语言环境机器上启动我的应用程序时,一切都很好,但在控制台中我有一条消息:

You are running Vue in development mode.
Make sure to turn on production mode when deploying for production.
See more tips at https://vuejs.org/guide/deployment.html

但是当我在 heroku 上启动我的应用程序时,我看不到 VueJS。我在控制台中有下一个错误。

[Vue warn]: Cannot find element: #app

这是我的一些文件: index.html.erb

<div id='app'>
<router-view></router-view>
</div>

应用程序.js

    import Vue from 'vue'
import VueRouter from 'vue-router'
import Vuex from 'vuex'
import VueResource from 'vue-resource'
import BaseStore from './store/base'

Vue.use(VueRouter)
Vue.use(Vuex)
Vue.use(VueResource)

import  Index from './templates/index.vue'
import Logs from './templates/logs.vue'
import Devices from './templates/devices.vue'


document.addEventListener('DOMContentLoaded', () =>{
  document.body.appendChild(document.createElement('app'))
  const router = new VueRouter({
    routes:[
      { path: '/' , component: Index , name: 'index'},
      { path: '/logs', component: Logs, name: 'logs'},
      { path: '/device', component: Devices, name: 'devices'}
    ]
  })

const store = new Vuex.Store(BaseStore)

const app = new Vue({
  router: router,
  store: store
}).$mount('#app')
})

【问题讨论】:

    标签: javascript ruby-on-rails vue.js heroku


    【解决方案1】:

    错误来自:document.body.appendChild(document.createElement('app'))

    这会创建一个&lt;app&gt; 节点,而不是&lt;div id="app"&gt; 节点,因此稍后.$mount("#app") 无法有效地找到该节点。

    将您的 document.createElement 部分替换为:

    const app = document.createElement('div')
    app.id = 'app'
    
    document.body.appendChild(app)
    

    应该可以的。

    【讨论】:

    • 如果这是一个可接受的答案,请将其标记为这样,以便其他访问此页面的人可以从您的体验中受益。
    猜你喜欢
    • 1970-01-01
    • 2014-08-26
    • 2019-01-09
    • 1970-01-01
    • 2018-07-31
    • 1970-01-01
    • 2014-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多