11<!DOCTYPE html>
22< html lang ="en ">
3+
34< head >
45 < meta charset ="UTF-8 ">
5- < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6- < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7- < title > Document</ title >
8- < script src ="https://unpkg.com/vue "> </ script >
9- < script src ="https://unpkg.com/marked@0.3.6 "> </ script >
10- < script src ="https://unpkg.com/lodash@4.16.0 "> </ script >
11- < style >
12- html , body , # editor {
13- margin : 0 ;
14- height : 100% ;
15- font-family : 'Helvetica Neue' , Arial, sans-serif;
16- color : # 333 ;
17- }
18-
19- textarea , # editor div {
20- display : inline-block;
21- width : 49% ;
22- height : 100% ;
23- vertical-align : top;
24- box-sizing : border-box;
25- padding : 0 20px ;
6+ < title > hello world</ title >
7+ < style type ="text/css " media ="screen ">
8+ .child-view {
9+ position : absolute;
10+ width : 100% ;
11+ transition : all .8s cubic-bezier (.55 , 0 , .1 , 1 );
2612 }
2713
28- textarea {
29- border : none;
30- border-right : 1px solid # ccc ;
31- resize : none;
32- outline : none;
33- background-color : # f6f6f6 ;
34- font-size : 14px ;
35- font-family : 'Monaco' , courier, monospace;
36- padding : 20px ;
14+ .slide-left-enter ,
15+ .slide-right-leave-active {
16+ opacity : 0 ;
17+ -webkit-transform : translate (500px , 0 );
18+ transform : translate (500px , 0 );
3719 }
3820
39- code {
40- color : # f66 ;
21+ .slide-left-leave-active ,
22+ .slide-right-enter {
23+ opacity : 0 ;
24+ -webkit-transform : translate (-500px , 0 );
25+ transform : translate (-500px , 0 );
4126 }
4227 </ style >
4328</ head >
29+
4430< body >
45- < div id ="editor ">
46- < textarea :value ="input " @input ="update "> </ textarea >
47- < div v-html ="compiledMarkdown "> </ div >
31+ < div id ="app ">
32+ < div >
33+ <!-- 4、<router-link>默认会被渲染成一个 `<a>` 标签 ,to指令跳转到指定路径 -->
34+ < router-link to ="/home "> Go to Home</ router-link >
35+ < router-link to ="/about "> Go to About</ router-link >
36+ </ div >
37+ <!-- 5、在页面上使用<router-view></router-view>标签,用于渲染匹配的组件 -->
38+ < transition :name ="transitionName ">
39+ < router-view class ="child-view "> </ router-view >
40+ </ transition >
4841 </ div >
42+ <!-- 组件 -->
43+ < template id ="Home ">
44+ < div >
45+ < h1 > {{msg}}</ h1 >
46+ </ div >
47+ </ template >
48+ < template id ="About ">
49+ < div >
50+ < h1 > {{msg}}</ h1 >
51+ </ div >
52+ </ template >
53+ <!-- 0、引入依赖库 -->
54+ < script src ="https://cdn.bootcss.com/vue/2.3.4/vue.min.js "> </ script >
55+ < script src ="https://cdn.bootcss.com/vue-router/2.7.0/vue-router.min.js "> </ script >
56+ < script type ="text/javascript ">
57+ /* 1、创建组件 */
58+ var Home = Vue . extend ( {
59+ template : '#Home' ,
60+ data : function ( ) {
61+ return {
62+ msg : 'Hello, vue router!'
63+ }
64+ }
65+ } ) ;
66+ var About = Vue . extend ( {
67+ template : '#About' ,
68+ data : function ( ) {
69+ return {
70+ msg : 'This is the tutorial about vue-router.'
71+ }
72+ }
73+ } ) ;
74+
75+ // 2. 创建 router 实例,然后传 `routes`路由映射 配置
76+ var router = new VueRouter ( {
77+ routes : [ {
78+ path : '/home' ,
79+ component : Home
80+ } , {
81+ path : '/about' ,
82+ component : About
83+ } , {
84+ path : '/' ,
85+ component : Home
86+ } //设置默认路径
87+ ]
88+ } ) ;
89+
90+ // 3. 创建和挂载根实例。记得要通过 router 配置参数注入路由,从而让整个应用都有路由功能
91+ var vm = new Vue ( {
92+ data : {
93+ transitionName : 'slide-left'
94+ } ,
95+ router : router
96+
97+ } ) . $mount ( '#app' ) ;
98+
99+ // 现在,应用已经启动了!
100+ </ script >
49101</ body >
50- < script >
51- new Vue ( {
52- el : '#editor' ,
53- data : {
54- input : '# hello'
55- } ,
56- computed : {
57- compiledMarkdown : function ( ) {
58- return marked ( this . input , { sanitize : true } )
59- }
60- } ,
61- methods : {
62- update : _ . debounce ( function ( e ) {
63- this . input = e . target . value
64- } , 300 )
65- }
66- } )
67- </ script >
102+
68103</ html >
0 commit comments