美文网首页
8.组件的基本使用

8.组件的基本使用

作者: 最爱喝龙井 | 来源:发表于2019-10-23 16:03 被阅读0次

组件的使用分三个步骤:
1.创建组件构造器 const cpnC = Vue.extend({template: html代码})
2.注册组件 Vue.component(自定义的标签名(注意必须是字符串格式),组件构造器名称)
3.启用组件 自定义的组件名

<div id="app">
        <cpn></cpn>
        <cpn></cpn>
        <cpn></cpn>
    </div>

    <script>
        const cpnC = Vue.extend({
            template: `
            <div>
                <h2>hello world</h2>
                <p>你好,世界</p>
            </div>
            `
        });
        Vue.component('cpn', cpnC);

        var vm = new Vue({
            el: '#app',
            data: {},
            methods: {}
        });
    </script>

相关文章

网友评论

      本文标题:8.组件的基本使用

      本文链接:https://www.haomeiwen.com/subject/lrykvctx.html