2020年8月16日日曜日

Vue: createdで実行したメソッドでdata要素に代入するには。

createdで実行してdataの要素に値を代入するには同期処理にしないとうまくいかなかった。
  export default {
    props: {
      prospectId: Number
    },
    data: function(){
      return {
        targetDate: null,
        categoryOptions: [],
        visitCategoryId: null
      }
    },
    created: function(){
      this.set_category_options();
    },
    methods : {
      set_category_options: async function() {
        const res = await axios.get('/visit_categories.json');
        this.categoryOptions = res.data;
      }
    }

0 件のコメント:

コメントを投稿