繁体   English   中英

Vue.js中的动态变量替换

[英]Dynamic variable substitution in vuejs

我有以下动态变量

{{地区}}

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

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

我试过了

{{#region.copy}}

这有可能吗

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

}

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

编辑:在计算变量中,您也可以使用this[region].copy而不是地理位置包裹

暂无
暂无

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

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