Vue组件化(全局、局部)、props传参

目录

全局组件化

带参数传递的全局组件化(props方式)

局部组件化

带参数传递的局部组件化(props方式)

自定义组件使用注意


全局组件化

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
		<script src="https://cdn.bootcss.com/vue/2.5.16/vue.js"></script>
	<script src="https://cdn.bootcss.com/axios/0.17.0/axios.min.js"></script>
</head>
<body>
	<!-- 第一种写法 -->
	<div id="box"><quanju></quanju></div>
	
	<!-- 第二种写法,写在网页端 -->
	<div id="div1"><seccc></seccc></div>
	
	<!-- 第二种写法,自定义内容(第二种推荐写法) -->
	<template id="tt3"><h1 @click="fn1()">自定义标签的第二种写法</h1><span></span></template>
	
	<script type="text/javascript">
		//全局组件化,格式: component(自定义标签名,标签和内容,但需要注意,根只有一个)
		//错误示范: template:"<div></div><div></div>" 必须只有一个大的范围包围,不能并行
		//第一种写法,可读性极差
		Vue.component("quanju",{template:"<h1>hello world </h1>"});
		var vm=new Vue({
			el:"#box"
		});

		//第二种写法,推荐
		Vue.component("seccc",
			{ 
			 template:"#tt3",
			 //也可以设置属性,但只能在组块内使用
			 data:function(){
			  	return {mes:"吴师傅",age:18}
			  },
			  methods:{
			  	fn1(){
			  		console.log("也可以有方法的哦");
			  	}
			  }
			})
		var tm=new Vue({
			el:"#div1"
		});
	</script>
</body>
</html>`

带参数传递的全局组件化(props方式)


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值