如何在Vue.js dev和Rails 4后端之间共享会话?

时间:2017-12-20 17:52:19

标签: ruby-on-rails ruby session vue.js vuejs2

我正在使用与Rails 4.2后端共存的Vue.js cli应用程序。

此处的目标是使用现有会话。当我为生产模式编译Vue.js应用程序时,我可以在开发模式下运行Rails服务器,并且可以从public目录正确地提供Vue应用程序,并且会话可以工作,因为它们是在同一个域上提供的。< / p>

尝试像这样进行开发和调试是非常困难的,因为您必须在测试之后编译Vue应用程序以进行生产,这也使得无法利用Vue Devtools进行调试。

如果我以开发模式提供Vue应用程序,这是通过webpack进行的,那么Vue应用程序和Rails应用程序是分开提供的,因此现在位于不同的域上,导致没有会话共享,不得不尝试处理CORS,等...

2 个答案:

答案 0 :(得分:0)

如果你可以的话,摆脱webpacker。 Vue可以很好地使用from cdn。 当在rails模板中实例化vue应用程序时,可以使用#{@model.to_json}轻松传递数据。

可以使用x-template语法在rails模板或资产管道中编写Vue组件。

答案 1 :(得分:-1)

There is an option in called proxyTable in the file config/index.js.

We were able to set the webpack root to proxy through the local Rails server by setting this option as proxyTable: {"/": "http://localhost:3000"}

3000 is the default port for a Rails dev server, but you may need to change this if you are running on a different port.