Vue组件的全局注册

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

</head>
<script src="./vue.js"></script>
<body>
    <div id="app">
             <my-com></my-com>  <!--直接写生组件名称就可以将template:'<div> hello World </div>' 中的文字显示出来 -->

    </div>
    
</body>
</html>

  //创建组件构造器 定义一个组件

        var myCompent=Vue.extend({

          template:'<div> hello World </div>' //template用来定义html部分

       })


  // 注册组件 第一个参数是组件名称 第二个参数是构造后的组件
  Vue.component('my-com',myCompent)

   注意 全局使用组件需要注册组件

posted @ 2017-09-14 22:41  Silly_Bo  阅读(304)  评论(0)    收藏  举报