forked from wakeupmypig/vue
-
Notifications
You must be signed in to change notification settings - Fork 1
/
22.组件.html
40 lines (40 loc) · 946 Bytes
/
22.组件.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<hello></hello>
<hello></hello>
<hello></hello>
</div>
<template id="tmpl">
<ul>
<li>home {{name}}</li>
<li>profile</li>
<li>concat</li>
</ul>
</template>
<script src="vue.js"></script>
<script>
//把html取出来当作模板,用数据渲染好,将我们的组件扔到页面里
//用extend方法创建出组建,在实例创建前
var hello = Vue.extend({
//template就是组件的模板
template:'#tmpl'
});
var world = Vue.extend({
//template就是组件的模板
template:'<div>world</div>'
});
//注册组件 第一个参数是组件的名字,第二个参数是创建的组件
Vue.component('hello',hello);
Vue.component('world',world);
var vm = new Vue({
el:'#app',
});
</script>
</body>
</html>