简体   繁体   English

生产模式问题(Rails 5.2.4.1 + VueJS + Webpack 3.12 + Heroku)

[英]Problem with production mode (Rails 5.2.4.1 + VueJS + Webpack 3.12 + Heroku)

I have a problem with production mode.我的生产模式有问题。 When I start my app on a locale machine everything is fine, but in console I have a message:当我在语言环境机器上启动我的应用程序时,一切都很好,但在控制台中我有一条消息:

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

But when I start my app on heroku I can't see VueJS.但是当我在 heroku 上启动我的应用程序时,我看不到 VueJS。 And I have the next error in console.我在控制台中有下一个错误。

[Vue warn]: Cannot find element: #app

Here is some my files: index.html.erb这是我的一些文件:index.html.erb

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

application.js应用程序.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')
})

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

This creates an <app> node, not a <div id="app"> node, so later on the .$mount("#app") cannot effectively find the node.这会创建一个<app>节点,而不是<div id="app">节点,因此稍后.$mount("#app")无法有效地找到该节点。

Replace your document.createElement part with:将您的document.createElement部分替换为:

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

document.body.appendChild(app)

That should do it.那应该这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM