2017-09-03 45 views
0

將數據分配到全局(Vue)對象 它正在進入(在debbuger上檢查它) 但返回到它的prev值當退出func時。從函數中分配給全局Vue對象的數據在退出函數後被「刪除」

我該怎麼做才能讓它留在那裏?

"use strict"; 

var App = 
{ 
    debugMode: 2,//0=no, 1=yes, 2=special deep debug :-(~) 
    serverApi: '../../Server/CrmAPI.php', 
    navTemplate: new Vue({el: '#menuTemplate', 

     data: { 
      objectName: "", 
      brandName: "CRM" 
     } 
    }), 
    currentObject: null // each time containes a different object that currently active by user selection 


} 


function navigateMainNav(selectedObj) 
{ 
    var objectName = selectedObj; //try 1 
    window.App.navTemplate.objectName = objectName; //try 2 
    App.navTemplate.data.objectName = objectName; // try 3 


    window.location.href = "../html/templates/navTemplate.html" ; // load html 

} 

回答

0

如果您想在Vue應用程序中使用全局數據,請考慮使用Vuex

它基本上是一個狀態管理器,可以將數據放入全局Vuex存儲中,可以從所有組件訪問它。

此外,在Vuex商店中放置全局內容可以防止您在js腳本中毒害全局命名空間。你應該檢查一下,它不像看起來那麼難! ;)