Global Component Example

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>

<body>
    <div id="app">
         <! - loop through the posts array when you call the component custom property assignment ->
        <boke v-for="post in posts" v-bind:id="post.id" v-bind:title="post.title" v-bind:content="post.content"></boke>
    </div>
    <script>
         // global registration component
        Vue.component (
         // Component name
            "boke", {
             // in the props list custom properties, custom properties can be any number
            props: ['title', 'id', 'content'],
             // access this value as the value of the data access component instance in the same html template
            template: "<div>{{id}}-----{{title}}-->{{content}}</div>",
        },

        );
         // global components can be instantiated any registered (by new Vue ()) the newly created use after it has been registered in
        There vm = new Vue ({
            el: "#app",
            data: {
                posts: [
                    {Id: 1, title: "Piece", content: 'dream of freedom and red red red'},
                    {Id: 2, title: 'Altman', content: 'peace earth fight'}
                ]
            }
        });
    </script>
</body>

</html>

Guess you like

Origin www.cnblogs.com/kukai/p/12391886.html