1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

propsで受け取った値を、チェックしてdataに格納する。

Last updated at Posted at 2019-10-11

受け取ったpropsの値をチェックしてからdataに格納したい。

親から子に値を渡す時は、子はpropsで受け取れます。
受け取った値を子コンポーネント側でチェックするにはどうしたらいいの?
...迷ったので忘備録です。

子コンポーネント

    props: {
      'oyaValue': {
        'type': [Array, Boolean, String],
        'default': false
      }
    },

    data: function(){
      const me = this;
      let checkVal = false;
      if(me.oyaValue) {
        checkVal = true;
      }
      return {
        'val': checkVal,
      };
    },

propsで受け取ったデータ(今回はoyaValue)を
チェックをしてdata内に入れる際は、
一旦ifでバリデーションをかけてから格納する。

今回は'oyaValue'から'val'にしてdata内に入れた。

ちなみにpropsの値を直接ゴニョゴニョ変更しようとすると怒られます。
※そうりゃそうやな、そもそもいじったらあかん。

簡単な記事だけど、とりあえず忘備録。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?