File tree Expand file tree Collapse file tree 2 files changed +63
-0
lines changed
Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change 1+ const atguigu = { }
2+
3+ atguigu . install = function ( Vue , options ) {
4+
5+ //添加两个全局指令
6+ Vue . directive ( 'upper-text' , function ( el , bingding ) {
7+ el . innerText = bingding . value . toUpperCase ( )
8+ } )
9+ Vue . directive ( 'lower-text' , function ( el , bingding ) {
10+ el . innerText = bingding . value . toLowerCase ( )
11+ } )
12+
13+ //给Vue自身添加属性
14+ Vue . projectName = '学生管理系统'
15+ Vue . MyVersion = 'V1.0.1'
16+ Vue . showINfo = function ( ) {
17+ console . log ( '我是一些信息' )
18+ }
19+
20+ //给Vue原型上添加数据,供vm使用
21+ Vue . prototype . $random = function ( min , max ) {
22+ return Math . floor ( Math . random ( ) * ( max - min ) + min )
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html >
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < title > 自定义插件</ title >
6+ < script type ="text/javascript " src ="../js/vue.js "> </ script >
7+ < script type ="text/javascript " src ="./atguigu.js "> </ script >
8+ </ head >
9+ < body >
10+ <!-- 准备好一个容器-->
11+ < div id ="root ">
12+ < h2 v-upper-text ="name "> </ h2 >
13+ < h2 v-lower-text ="name "> </ h2 >
14+ < h2 > {{$random(2,8)}}</ h2 >
15+ </ div >
16+
17+ < script type ="text/javascript " >
18+ /*
19+ 插件的定义:是一个包含install方法的对象
20+ */
21+ Vue . config . productionTip = false //关闭生产提示
22+
23+ //Vue会帮我们去调用atguigu这个插件里的install方法
24+ Vue . use ( atguigu )
25+
26+ console . log ( Vue . projectName )
27+ console . log ( Vue . MyVersion )
28+ Vue . showINfo ( )
29+
30+ const vm = new Vue ( {
31+ el :'#root' ,
32+ data :{
33+ name :'atGuiGu'
34+ }
35+ } )
36+
37+ </ script >
38+ </ body >
39+ </ html >
You can’t perform that action at this time.
0 commit comments