【问题标题】:Dynamic variable substitution in vuejsvuejs中的动态变量替换
【发布时间】:2018-02-06 16:26:06
【问题描述】:

我有以下动态变量

{{ 地区 }}

可以等于北、南、东或西。

我想用它从我的数据对象中提取变量

我试过了

{{ #region.copy }}

这在vue中可以吗

data: function() {
    return {
             north : {
                copy: "this is the north copy"
            },
            south : {
                copy: "this is the north copy"
            }

}

【问题讨论】:

  • “拉取适当的副本”是什么意思?
  • 复制什么?你能稍微解释一下吗?也许提供更多关于你在做什么的代码。
  • 抱歉 - 已更新,只是我的数据对象中的一个字符串。

标签: variables vuejs2 substitution dynamic-variables


【解决方案1】:

您可以在对象地理中放置北、南、东和西。在地理上,您可以通过geo[region].copy 访问您所在的地区。如果region === south 将导致geo.south.copy

编辑:在计算变量中,您还可以使用 this[region].copy 代替地理包装

【讨论】:

    猜你喜欢
    • 2020-11-04
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多