2017-03-05 72 views
0

我目前正在使用Vue組件內的moment.js,但我沒有看到在vue devtools中顯示的某些更改。Vue.js devtool更改不顯示

我的例子:

export default { 
    data() { 
     return { 
      moment: moment(), 

     }; 
    }, 
    methods: { 
     prevMonth() { 
      this.moment.subtract(7, 'days'); 
     }, 
     nextMonth() { 
      this.moment.add(7, 'days'); 
     } 
    } 
}; 

我猜這事做的事實,我呼籲我的時刻數據屬性的方法,而不是直接像一些操縱它。像這樣的例子完美的作品,並更新VUE devtools我計數:

export default { 
    data() { 
     return { 
      count: 0, 

     }; 
    }, 
    methods: { 
     prevMonth() { 
      this.count--; 
     }, 
     nextMonth() { 
      this.count++; 
     } 
    } 
}; 

有沒有什麼辦法來迫使VUE devtools重載或展示我以任何方式改變?

+0

可能的重複[爲什麼vue.js沒有使用date.js更新datepicker的dom](http://stackoverflow.com/questions/40959483/why-does-vue-js-not-update-the- DOM與 - 日期選擇 - 使用矩-JS) – Saurabh

回答

1

Vue無法檢測到對象內部的某些更改,請從官方文檔中閱讀this explanation以更好地理解它。

我認爲最簡單的方法做你正在嘗試什麼實現的是從你現有的在你的prevMonth/nextMonth方法使一個新的日期,並將其分配給this.moment,像這樣:

prevMonth() { 
    this.moment = moment(this.moment).subtract(1, 'month'); 
}, 

working JSFiddle example