2017-08-16 57 views
0

我對VueJS有一個愚蠢的問題。我是VueJS的新手。我想訪問和更改數據函數的變量。但是我做不到。如何在VueJS上使用數據函數的變量?

線這是越來越錯誤:

console.log('item: ' + this.item);

錯誤是在這裏:

TypeError: Cannot read property 'item' of undefined

這裏是我的代碼:

data: function(){ 
    return { 
     item: 69, 
     file: 0 
    }; 
}, 

methods: { 
    toggle: (elementId = 0, type = 'item') => { 
     console.log('element ID: ' + elementId); 
     console.log('type: ' + type); 
     console.log('item: ' + this.item); 

     switch (type) { 
      case 'item': 
       break; 
      case 'file': 
       break; 
     } 
    } 
} 
+0

'console.log('item:'+ this.item);'這不是錯誤 – smarber

+0

也分享錯誤訊息。 –

+0

好吧,郵件已根據您的意願更新。 –

回答

相關問題