Vue.js 第十三节:组件注册 复现

组件注册

局部注册

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<script type='text/javascript' src='vue.js'></script>
		<title></title>
	</head>
	<body>
		<div id='app'>			
			<test></test>
			<!-- 用test标签就可以实现局部注册 -->
		</div>
		<script type="text/javascript">	
			var vm = new Vue({
				el: '#app',		
				components:{	
					// data: {
					// 	count: 0
					// },  这个变量应该怎么注册??
					test: {
						template:'<h1>简单测试</h1>'
						// template:'<div><h1>hi, little potato!</h1><br><button v-on:click="count++">被点击了{{count}}次</button><slot></slot></div>',
					}
				}
				
			});
		</script>
	</body>
</html>

  • 如何在局部注册中引入变量值呢?

在模块系统中局部注册

若使用了Babel和wepack的模块系统,在这种情况下我们推荐使用创建一个components目录,并将每个组件防治在各自的文件中.已如下语句进行引入.
import ComponentA from …

  • 有待进一步研究…
发布了10 篇原创文章 · 获赞 0 · 访问量 160

猜你喜欢

转载自blog.csdn.net/yjj510818155/article/details/104761129
今日推荐