[Vuejs]-Vue.js How to watcher before mounted() , can't get data from watch

1👍

From you code, it seems like a computed would do the job. Try moving your logic from mounted() to computed as

computed: {
    dataPreset() {
        return [this.p1, this.p2];
    }
 }

This would automatically return an updated dataPreset whenever p1 or p2 change.

EDIT:

As far as I have understood, you can definitely initialize your graph once you have the API data inside your watcher. You watcher could be like

watch: {
    selectedTrend: {
      immediate: true,
      handler(to) {
        this.trend = to.Trends;
        this.GetAPIData(to.Trends, to.DT);  //A method to get the sample API DATA
        this.InitializeGraph(); //A method which initializes your graph
      }
    }
  },

A sample sandbox created at: https://codesandbox.io/s/twitter-trends-fp0wn

Leave a comment