Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 获取方法';将rails(后端)的响应写入Vue模块_Ruby On Rails_Vue.js - Fatal编程技术网

Ruby on rails 获取方法';将rails(后端)的响应写入Vue模块

Ruby on rails 获取方法';将rails(后端)的响应写入Vue模块,ruby-on-rails,vue.js,Ruby On Rails,Vue.js,我在助手模块中定义了一个方法,它根据条件返回一个常量: def contact_us_link current_user.new_user? ? NEW_CONTACT_US : OLD_CONTACT_US end 现在,我想在我的Vue模块中使用相同的方法,以前在constants.js中将单个常量定义为OLD\u CONTACT\u US My Vue组件通过以下方式返回数据来使用常量: data() { return { contactUsUrl:

我在助手模块中定义了一个方法,它根据条件返回一个常量:

  def contact_us_link
    current_user.new_user? ? NEW_CONTACT_US : OLD_CONTACT_US
  end
现在,我想在我的Vue模块中使用相同的方法,以前在
constants.js
中将单个常量定义为
OLD\u CONTACT\u US

My Vue组件通过以下方式返回数据来使用常量:

data() {
    return {
      contactUsUrl: OLD_CONTACT_US,
    }
  }
我的HTML代码如下所示:

<a
:href="contactUsUrl"
target="_blank"
class="stl-text-secondary-0 stl-text-medium contact-us-link"
>Contact Us</a>


我需要将Url的值从我的助手模块中的方法获取到我的Vue组件中。

当您尝试在Vue或任何其他JS框架中组合Rails varialbe/方法时,您必须使用erb/slim文件。在这里,您将js的变量赋值为ruby method或variable。或者向rails api发送请求并在json响应中获取值。只有两条路。