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 コンポーネント作成

Posted at

コンポーネントを作成する

グローバル登録、ローカル登録、シングルファイルコンポーネントの作成方法がある

    <div id="app">
        <paragraph></paragraph>
    </div>
    <script>
        Vue.component('paragraph',{
            data:function(){
                return {
                    counter: 0
                }
            },
            template:'<div><button @click="counter++">{{counter}}</button></div>'
        })
    </script>

<paragraph message="hello"></paragraph>
messageプロパティを受け取り表示させる

    <div id="app">
        <paragraph message="hello"></paragraph>
        <paragraph message="world"></paragraph>
    </div>
    <script>
        Vue.component('paragraph',{
            props:['message'],
            template:'<div>{{ message }}</div>'
        })

プロパティの値が長い場合、<slot></slot>で同様の動きが可能

    <div id="app">
        <paragraph>hellohellohello</paragraph>
    </div>
    <script>
        Vue.component('paragraph',{
            template:'<div><slot></slot></div>'
        })
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?