vue.js 全局组件学习笔记

用法:

注册或获取全局组件。

// 注册组件,传入一个扩展过的构造器
Vue.component('my-component', Vue.extend({ /* ... */ }))

// 注册组件,传入一个选项对象 (自动调用 Vue.extend)
Vue.component('my-component', { /* ... */ })

// 获取注册的组件 (始终返回构造器)
var MyComponent = Vue.component('my-component')
<div id="components-demo">
  <button-counter></button-counter>
</div>

new Vue({ el: '#components-demo' })

示例demo:(曾经在学习练习的时候遇到的错误)

<div id="app2">
    <button-self></button-self>
</div>
Vue.component('button-self',{
    data:function(){
        return {
	    count:0
	}
    },
    template:'<button>您点击了{{count}}次</button>'
})

new Vue({el:"#app2"})
注意:创建Vue实例要放到组件下面,否则会报错vue.js提示 Unknown custom element: <button-self>- did you register the component correctly? For recurs



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值