2017-09-01 91 views
0

我正在嘗試使用vue和axios加載cytoscape圖。無論如何不能配置cytoscape,所以我首先嚐試與axios和vue只。範圍仍然存在問題,但我不知道在哪裏?我應該改變什麼?如何正確設置vue和axios。Axios無法將數據加載到vue

編輯

所以設置this.nodes後,我想提請在cytoscape.js一個grapg,但我總是得到錯誤:

-The樣式屬性text-outline-color:無效

- 不要將映射分配給沒有相應數據的元素(例如ele 6b899f09-359e-424d-9461-d71c8c3fcd3b對於屬性text-outline-color與數據字段faveColor);嘗試[faveColor]選擇限制範圍與faveColor元素定義

-Uncaught類型錯誤:空

不能設置屬性「映射」我相信這是陣列的問題,但我無法弄清楚如何設置陣列正確,這可以工作。

這裏是代碼:

draw: function(){ 

    this.cy = cytoscape({ 
      container: document.getElementById('cy'), 
       layout: { 
       name: this.main_layout, 
       padding: 10 
       }, 
       style: cytoscape.stylesheet() 
       .selector('node') 
        .css({ 
        'shape': 'data(faveShape)', 
        'width': 'mapData(weight, 40, 80, 20, 60)', 
        'content': 'data(name)', 
        'text-valign': 'center', 
        'text-outline-width': 2, 
        'text-outline-color': 'data(faveColor)', 
        'background-color': 'data(faveColor)', 
        'color': '#fff' 
        }) 
       .selector(':selected') 
        .css({ 
        'border-width': 3, 
        'border-color': '#333' 
        }) 
       .selector('edge') 
        .css({ 
        'curve-style': 'bezier', 
        'opacity': 0.666, 
        'width': 'mapData(strength, 70, 100, 2, 6)', 
        'target-arrow-shape': 'triangle', 
        'source-arrow-shape': 'circle', 
        'line-color': 'data(faveColor)', 
        'source-arrow-color': 'data(faveColor)', 
        'target-arrow-color': 'data(faveColor)' 
        }) 
       .selector('edge.questionable') 
        .css({ 
        'line-style': 'dotted', 
        'target-arrow-shape': 'diamond' 
        }) 
       .selector('.faded') 
        .css({ 
        'opacity': 0.25, 
        'text-opacity': 0 
        }), 
       elements: { 
       nodes: this.nodes 

       }, 

       ready: function(){ 
       window.cy = this; 
       } 
      }); 

回答

0

我假定response.data爲數組或ANS vm.projektnull沒有VUE-吸氣registred對象。所以,請試着做

Vue.set(vm, 'projekt', response.data)也有在每VUE實例(本)

代替

vm.projekt = response.data

一般而言,$組我勸你推Ajax的DATAS成反應式陣列,這工作得很好。

+0

如果我這樣做,在控制檯中我仍然得到空。怎麼了?這裏是jsbin [link] https://jsbin.com/piwusuyici/edit?js我正在使用npm。 – Tim

+0

jsbin不起作用。你試圖得到的網址可能是錯誤的。你沒有一個範圍問題。 – Reiner

+0

這只是代碼。但爲什麼我仍然在console.log(this.projekt)中變爲空? – Tim

相關問題