File tree Expand file tree Collapse file tree 2 files changed +67
-13
lines changed
Expand file tree Collapse file tree 2 files changed +67
-13
lines changed Original file line number Diff line number Diff line change @@ -23,4 +23,44 @@ Fibonacci数列第N项 (斐波那契数列)
2323 return fib (n- 1 ) + fib (n- 2 );
2424 }
2525 console .log (fib (5 ));
26+ ```
27+
28+ ## match
29+
30+ match() 方法可在字符串内检索指定的值,或找到一个或多个正则表达式的匹配。
31+
32+ ``` js
33+ < script type= " text/javascript" >
34+
35+ var str= " Hello world!"
36+ document .write (str .match (" world" ) + " <br />" )
37+ document .write (str .match (" World" ) + " <br />" )
38+ document .write (str .match (" worlld" ) + " <br />" )
39+ document .write (str .match (" world!" ))
40+
41+ < / script>
42+ ```
43+
44+ 输出
45+
46+ ``` js
47+ world
48+ null
49+ null
50+ world!
51+ ```
52+
53+ ``` js
54+ < script type= " text/javascript" >
55+
56+ var str= " 1 plus 2 equal 3"
57+ document .write (str .match (/ \d + / g ))
58+
59+ < / script>
60+ ```
61+
62+ 输出
63+
64+ ``` js
65+ [1 , 2 , 3 ]
2666```
Original file line number Diff line number Diff line change @@ -19,6 +19,24 @@ author: gaoyang
1919
2020 3.它本身只关注UI, 可以轻松引入vue插件或其它第三库开发项目
2121
22+
23+
24+
25+
26+ # 双向绑定原理
27+
28+ vue数据双向绑定是通过数据劫持结合发布者-订阅者模式的方式来实现的。
29+
30+ 我们已经知道实现数据的双向绑定,首先要对数据进行劫持监听,所以我们需要设置一个监听器Observer,用来监听所有属性。如果属性发上变化了,就需要告诉订阅者Watcher看是否需要更新。因为订阅者是有很多个,所以我们需要有一个消息订阅器Dep来专门收集这些订阅者,然后在监听器Observer和订阅者Watcher之间进行统一管理的。接着,我们还需要有一个指令解析器Compile,对每个节点元素进行扫描和解析,将相关指令(如v-model,v-on)对应初始化成一个订阅者Watcher,并替换模板数据或者绑定相应的函数,此时当订阅者Watcher接收到相应属性的变化,就会执行对应的更新函数,从而更新视图。因此接下去我们执行以下3个步骤,实现数据的双向绑定:
31+
32+ 1.实现一个监听器Observer,用来劫持并监听所有属性,如果有变动的,就通知订阅者。
33+
34+ 2.实现一个订阅者Watcher,每一个Watcher都绑定一个更新函数,watcher可以收到属性的变化通知并执行相应的函数,从而更新视图。
35+
36+ 3.实现一个解析器Compile,可以扫描和解析每个节点的相关指令(v-model,v-on等指令),如果节点存在v-model,v-on等指令,则解析器Compile初始化这类节点的模板数据,使之可以显示在视图上,然后初始化相应的订阅者(Watcher)。
37+
38+ ` https://www.jianshu.com/p/f194619f6f26 ` 详解
39+
2240# vue的原理分析
2341
2442## 数据代理
@@ -37,12 +55,6 @@ author: gaoyang
3755
3856 c.getter/setter内部去操作data中对应的属性数据
3957
40-
41-
42-
43-
44-
45-
4658## 模板解析
4759
4860模板解析的基本流程
@@ -825,20 +837,22 @@ params方式传参和接收参数
825837
826838``` js
827839this .$router .push ({
828- path : ' /xxx '
829- query : {
830- id: id
831- }
832- })
840+ name : ' dispatch ' ,
841+ params : {
842+ id: id
843+ }
844+ })
833845```
834846
835847接收参数:
836848
837849``` js
838- this .$route .query .id
850+ this .$route .params .id
839851```
840852
841- 注意: params 传参,push里面只能是 name:'xxxx',不能是path:'/xxx',因为params只能用name来引入路由,如果这里写成了path,接收参数页面会是undefined!!!
853+ 注意: params 传参,push里面只能是 name:'xxx',不能是path:'/xxx',因为params只能用name来引入路由,如果这里写成了path,接收参数页面会是undefined!!!
854+
855+ 另外,二者还有点区别,直白的来说query相当于get请求,页面跳转的时候,可以在地址栏看到请求参数,而params相当于post请求,参数不会再地址栏中显示
842856
843857# vuex
844858
You can’t perform that action at this time.
0 commit comments