Vue-component

组件(Component)是 Vue.js 最强大的功能之一。

组件可以扩展 HTML 元素,封装可重用的代码。

组件系统让我们可以用独立可复用的小组件来构建大型应用,几乎任意类型的应用的界面都可以抽象为一个组件树。

Vue data访问

<!-- prop -->

<div style="height: 150px;background: #CCC;margin: 5px;">

<div style="font-size: 20px;">

v2.prop属性</div>

<hr />

<div>

<div>

<comp05 msg="13579"></comp05>

</div>

</div>

</div>

 

<!-- 局部组件 -->

<div style="height: 150px;background: #CCC;margin: 5px;">

<div style="font-size: 20px;">

v1.局部组件</div>

<hr />

<div>

<div>

<comp03></comp03>

</div>

</div>

</div>

 

<!-- 全局组件 -->

<div style="height: 150px;background: #CCC;margin: 5px;">

<div style="font-size: 20px;">

v0.全局组件</div>

<hr />

<div>

<div>

<comp01></comp01>

</div>

</div>

</div>

 

<script>

/* 全局组件 */

Vue.component(

'comp01', {

template: '<h2>自定义组件!</h2>'

}

);

/* 通过 props 把数据传给子组件 */

Vue.component(

'comp05', {

props: ['msg'],

template: '<h4>{{msg}}</h4>'

}

);

new Vue({

el: "#appVue",

data: {

count: 999

},

/* 局部组件 */

components: {

'comp03': {

template: '<h3>自定义组件!</h3>'

}

}

}

 

)

</script>

 

<!DOCTYPE html>
<html style="height: 100%;">

	<head>
		<meta charset="UTF-8">
		<script type="text/javascript" src="../lib/vue.v2.5.12.js"></script>
		<title>v-xxx</title>
	</head>

	<body style="height: 100%;">
		<style>
			.style0 {
				font-size: 25px;
				color: green;
			}
			
			.style1 {
				background: gold;
			}
		</style>
		<!-- 
			VUE组件
				
			REF:
				http://www.runoob.com/vue2/vue-component.html
				https://cn.vuejs.org/v2/guide/components.html
		-->
		<div id="appVue">
			<!-- prop -->
			<div style="height: 150px;background: #CCC;margin: 5px;">
				<div style="font-size: 20px;">
					v2.prop属性</div>
				<hr />
				<div>
					<div>
						<comp05 msg="13579"></comp05>
					</div>
				</div>
			</div>			
			
			<!-- 局部组件 -->
			<div style="height: 150px;background: #CCC;margin: 5px;">
				<div style="font-size: 20px;">
					v1.局部组件</div>
				<hr />
				<div>
					<div>
						<comp03></comp03>
					</div>
				</div>
			</div>			
			
			<!-- 全局组件 -->
			<div style="height: 150px;background: #CCC;margin: 5px;">
				<div style="font-size: 20px;">
					v0.全局组件</div>
				<hr />
				<div>
					<div>
						<comp01></comp01>
					</div>
				</div>
			</div>
		</div>
		<script>
			/* 全局组件 */
			Vue.component(
				'comp01', {
					template: '<h2>自定义组件!</h2>'
				}
			);
			/* 通过 props 把数据传给子组件 */
			Vue.component(
				'comp05', {
					props:['msg'],
					template: '<h4>{{msg}}</h4>'
				}
			);			
			new Vue({
					el: "#appVue",
					data: {
						count: 999
					},
					/* 局部组件 */
					components: {
						'comp03': {
							template: '<h3>自定义组件!</h3>'
						}
					}
				}

			)
		</script>
	</body>

</html>

REF:

http://www.runoob.com/vue2/vue-component.html

https://cn.vuejs.org/v2/guide/components.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值