简体   繁体   English

Vue.js中的动态变量替换

[英]Dynamic variable substitution in vuejs

I have the following dynamic var 我有以下动态变量

{{ region }} {{地区}}

which could equal north, south, east or west. 可以等于北,南,东或西。

I want to use it to pull in the variable from my data object 我想用它从我的数据对象中提取变量

I tried 我试过了

{{ #region.copy }} {{#region.copy}}

Is this possible in vue 这有可能吗

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

} }

You can put north, south, east and west in an object geo. 您可以将北,南,东和西放置在对象地理区域中。 In geo you can access your region by geo[region].copy . 在geo中,您可以通过geo[region].copy访问您的区域。 If region === south it will result in geo.south.copy 如果region === south ,将导致geo.south.copy

Edit: in computed variables you can also use this[region].copy instead of a geo wrap 编辑:在计算变量中,您也可以使用this[region].copy而不是地理位置包裹

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

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