点击了{{count}}次', methods:{ handle:function(){ this.count++; } } }) varvm=newVue({ el:'#app', data:{ } });

如何在页面中运用,直接在页面中应用组件名称



这个组件是可以重用的,直接在页面中多次使用,切数据相互独立,互不干扰

组件注册注意事项

1.data必须是一个函数

2.组件模板内容必须是单个根元素

3.组件模板内容可以是模板字符串

4.组件命名方式

Vue.component('my-component',{/*...*/})

驼峰方式

Vue.component('MyComponent',{/*...*/})

如果使用驼峰式命名组件,那么在使用组件的时候,只能在字符串模板中用驼峰的方式使用组件,但是在普通的标签模板中,必须使用短横线的方式使用组件

局部组件

局部组件只能在注册它的父组件中使用

局部组件注册语法

varComponentA={/*...*/}
varComponentB={/*...*/}
varComponentC={/*...*/}
newVue({
el:'#app',
components:{
'component-a':ComponentA,
'component-b':ComponentB,
'component-c':ComponentC
}
})

组件的创建

Vue.component('test-com',{
template:'
Test
' }); varHelloWorld={ data:function(){ return{ msg:'HelloWorld' } }, template:'
{{msg}}
' }; varHelloTom={ data:function(){ return{ msg:'HelloTom' } }, template:'
{{msg}}
' }; varHelloJerry={ data:function(){ return{ msg:'HelloJerry' } }, template:'
{{msg}}
' }; varvm=newVue({ el:'#app', data:{ }, components:{ 'hello-world':HelloWorld, 'hello-tom':HelloTom, 'hello-jerry':HelloJerry } });

页面中的应用






以上就是Vue组件注册全解析的详细内容,更多关于Vue组件注册的资料请关注毛票票其它相关文章!

热门推荐

1 毛坯房验收经验和常识 看了之后再验房心里有底
2 二手房收房如何交接 二手房收房注意问题
3 专业验收毛坯房的价格 商品房验收合格的标准
4 精装房怎么验收 精装房请验房师有用吗
5 一般要到哪里找验房师 验房师有哪些作用呢
6 请人验房一般是多少钱 验房师费用是多少
7 怎样测量房子面积 建筑面积和使用面积怎么算
8 收房需要注意什么 仔细检查不松懈
9 收房时三书一证一表是什么 主要作用介绍
10 交房时交房税费有哪些 本文为你一一讲解
11 验房都需要验什么 要做哪些准备呢
12 毛坯房验房师有必要请吗 毛坯房装修完如何验收
13 地下室防水工程质量验收规范详解
14 水性涂料、油性涂料区别介绍
15 零基础布艺DIY工坊 教你做超萌猫头鹰钥匙包
16 三棵树漆怎么样?三棵树漆官方网站
17 家庭“装修套餐”中猫腻你知道吗?
18 小空间大浴望 卫浴间装修巧支招