Skip to content

Commit c0d2aa0

Browse files
author
人心思动
authored
Add files via upload
1 parent b94e073 commit c0d2aa0

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

vue2.0学习/Vue.extend.html

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>定义组件的两种方式</title>
7+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
8+
</head>
9+
10+
<body>
11+
<div id="itany">
12+
<hello></hello>
13+
<my-world></my-world>
14+
</div>
15+
16+
<script>
17+
/**
18+
* 方式1:先创建组件构造器,然后由组件构造器创建组件
19+
*/
20+
//1.使用Vue.extend()创建一个组件构造器
21+
var MyComponent = Vue.extend({
22+
template: '<h3>Hello World</h3>'
23+
});
24+
//2.使用Vue.component(标签名,组件构造器),根据组件构造器来创建组件
25+
Vue.component('hello', MyComponent);
26+
27+
/**
28+
* 方式2:直接创建组件(推荐)
29+
*/
30+
// Vue.component('world',{
31+
Vue.component('my-world', {
32+
template: '<h1>你好,世界</h1>'
33+
});
34+
35+
var vm = new Vue({ //这里的vm也是一个组件,称为根组件Root
36+
el: '#itany',
37+
data: {
38+
msg: '前端'
39+
}
40+
});
41+
</script>
42+
</body>
43+
44+
</html>

0 commit comments

Comments
 (0)