Skip to content

Commit 7f25390

Browse files
committed
更新
1 parent a4bfea9 commit 7f25390

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

18_组件_非单文件/非单文件组件.html

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
1.定义组件:Vue.extend(options)
1212
2.注册组件:
1313
全局注册:Vue.component('组件名',组件)
14-
局部注册
14+
局部注册:配置components属性,components:{组件名:组件}
1515
3.写组件标签
1616
-->
1717
<!-- 准备好一个容器-->
1818
<div id="root">
19+
<Hello></Hello>
1920
<School></School>
2021
</div>
2122

@@ -33,7 +34,16 @@
3334
(3).组件的模板结构,要配置在template属性中:
3435
(3.1)值为html字符串,而且要用模板字符串。
3536
(3.2)模板结构,必须只有一个跟标签。
37+
4.所有的组件定义后,必须注册才能使用,注册分为:全局注册、局部注册
38+
5.特别注意:
39+
(1).School确实是构造函数,但不是我们亲手写的School,是Vue.extend生成的。
40+
(2).Vue.extend调用的返回值是VueComponent构造函数,所以new School其实就是在new VueComponent。
41+
(3).所谓组件实例,就是VueComponent创建的实例,简称vc。
42+
所有Vue实例,就是Vue创建的实例,简称vm
43+
6.一个最最最重要的关系:
44+
VueComponent继承了Vue,所以Vue.prototype上的属性和方法,vc都能看得见
3645
*/
46+
3747
const School = Vue.extend({
3848
//data中存放组件所需数据
3949
data(){
@@ -50,16 +60,22 @@ <h2>学校地址:{{address}}</h2>
5060
</div>
5161
`
5262
})
63+
Vue.prototype.xyz = 1
64+
//定义个Hello组件
65+
const Hello = Vue.extend({
66+
template:`<h2>Hello</h2>`
67+
})
5368

5469
//注册School组件----全局注册
5570
// Vue.component('School',School)
5671

5772
//定义一个vm,去管理所有的组件
58-
new Vue({
73+
const vm = new Vue({
5974
el:'#root',
60-
//注册School组件----局部注册
75+
//注册School组件----局部注册----以后工作用的多
6176
components:{
62-
School
77+
School,
78+
Hello
6379
}
6480
})
6581
</script>

复习/7.模拟Vue.extend.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Document</title>
6+
</head>
7+
<body>
8+
<script type="text/javascript" >
9+
10+
//模拟Vue.extend
11+
/* const Vue = {
12+
extend(){
13+
function VueComponent(){
14+
15+
}
16+
return VueComponent
17+
}
18+
}
19+
const School = Vue.extend()
20+
const s = new School()
21+
console.log(s) // */
22+
</script>
23+
</body>
24+
</html>

复习/8.继承与原型链.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Document</title>
6+
</head>
7+
<body>
8+
<script type="text/javascript" >
9+
10+
class Person {}
11+
Person.prototype.b = 200
12+
13+
class Student extends Person{
14+
name = 'tom'
15+
}
16+
Student.prototype.a = 100 //a想给s用
17+
18+
const s = new Student()
19+
20+
console.log(s.b)
21+
</script>
22+
</body>
23+
</html>

0 commit comments

Comments
 (0)