zoukankan      html  css  js  c++  java
  • Vue2 组件注册

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <script type="text/javascript" src="Vue-v2.5.22.js"></script>
        <title>Title</title>
    </head>
    <body>
    <div id="app">
        <my-component></my-component>
        <my-parent></my-parent>
    
        <my-component2></my-component2>
        <my-parent2></my-parent2>
    </div>
    
    <script type="text/javascript">
        // 全局注册
        let MyComponent = Vue.extend({
            template: '<p>This is a component</p>'
        });
    
        Vue.component('my-component', MyComponent);
    
        // 局部注册
        let Child = Vue.extend({
            template: '<p>This is a child component</p>'
        });
    
        let Parent = Vue.extend({
            template: '<div>
            <p>This is a parent component</p>
            <my-child></my-child>
            </div>',
            components: { //注意加 s
                'my-child': Child
            }
        });
    
        Vue.component('my-parent', Parent);
    
        // 简化方式
        // 全局注册
        Vue.component('my-component2',
            {
                template: '<p>This is a component</p>'
            });
        // 局部注册
        Vue.component('my-parent2',
            {
                template: '<div>
            <p>This is a parent component</p>
            <my-child2></my-child2>
            </div>',
                components: { //注意加 s
                    'my-child2': {
                        template: '<p>This is a child component</p>'
                    }
                }
            });
    
        let vm = new Vue({
            el: '#app',
        })
    </script>
    </body>
    </html>
  • 相关阅读:
    python中open函数的使用
    内存地址转换与分段【转】
    VirtualBox虚拟机网络设置【转】
    Google免费的公共DNS服务器
    SSH数据交互过程【转】
    适合Web服务器的iptables规则【转】
    使用安装光盘建立本地yum仓库【转】
    RHCE从入门到精通视频教程【转】
    解决Apache启动时错误提示
    50个C/C++源代码网站【转】
  • 原文地址:https://www.cnblogs.com/wjlbk/p/12633469.html
Copyright © 2011-2022 走看看