0
0

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.

Vue.jsの"なければならない"

0
Last updated at Posted at 2019-10-04

コンポーネント

dataは関数でなければならない

Vue.component('my-component', {

...

   data: function () {
      return {
         message: 'Hello Vue.js'
      }
   }
})

テンプレートの要素は一つでなければならない

templatel: '<span>a</span><span>b</span>'

↑はNG

template: '<div><span>a</span><span>b</span></div>'

のように大きく一つにまとめればOK

.nativeで発火

コンポーネント内でv-onを使いたいときは、.nativeをつけなければならない.

<my-component v-on:click="eventClick"></my-component>

↑ではクリックしても、eventClickは実行されない。
この場合実行するには、子コンポーネントで$emitを使って発火しなければならない。

これを回避するには、

<my-component v-on:click.native="eventClick"></my-component>

とすればよい。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?