2017-03-03 23 views
0

我有一個頁面,其中字段名稱的類型是數組。在Vuejs中用括號指定數據的最佳方法是什麼?

eg. mapping[map][email_address][type] 

現在Vue公司,我想設置的默認值,我做如下

new Vue({ 
    el: '#configure', 
    data: { 
     mapping: { 
      map: { 
       email_address: { 
        type: 'incoming_field' 
       } 
      } 
     } 
    } 
}) 

但我在控制檯得到一個錯誤

[Vue warn]: Property or method "map" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option. 

vue.js:569 [Vue warn]: Property or method "email_address" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option. 

vue.js:569 [Vue warn]: Error in render function: 
(found in <Root>) 

什麼在Vuejs中處理這些字段名稱的最佳方法是什麼?

回答

0

與參數你的代碼,你要做的:

mapping['map']['email_address']['type'] 

mapping.map.email_address.type 
0

你應該重新考慮你的數據不會有這麼多嵌套對象。

如果您直接在對象內設置屬性,最好使用Vue.set來確保you do not break reactivity。這樣做可以節省您數小時的頭痛,試圖找出破壞的地方。

Vue.set(mapping.map.email_address, 'type', value_to_set) 
相關問題