1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| import Vue from "vue/dist/vue"; import VueRouter from "vue-router"; Vue.use(VueRouter);
const Home = { template: "<div>我是 Home 页</div>" }; const Foo = { template: "<div>我是 foo 页</div>" }; const Bar = { template: "<div>我是 bar 页</div>" };
const routes = [ { path: "/", component: Home }, { path: "/foo", component: Foo }, { path: "/bar", component: Bar } ];
const router = new VueRouter({ routes });
new Vue({ router, template: ` <div id="app"> <h1>Hello Vue-router </h1> <ul> <li><router-link to="/">/</router-link></li> <li><router-link to="/foo">/foo</router-link></li> <li><router-link to="/bar">/bar</router-link></li> </ul> router-view content: <router-view class="view"></router-view> </div> `, beforeCreate: function() { console.group("beforeCreate 创建前状态===============》"); console.log("%c%s", "color:red", "el : " + this.$el); console.log("%c%s", "color:red", "data : " + this.$data); console.log("%c%s", "color:red", "message: " + this.message); }, created: function() { console.group("created 创建完毕状态===============》"); console.log("%c%s", "color:red", "el : " + this.$el); console.log("%c%s", "color:red", "data : " + this.$data); console.log("%c%s", "color:red", "message: " + this.message); }, beforeMount: function() { console.group("beforeMount 挂载前状态===============》"); console.log("%c%s", "color:red", "el : " + this.$el); console.log(this.$el); console.log("%c%s", "color:red", "data : " + this.$data); console.log("%c%s", "color:red", "message: " + this.message); }, mounted: function() { console.group("mounted 挂载结束状态===============》"); console.log("%c%s", "color:red", "el : " + this.$el); console.log(this.$el); console.log("%c%s", "color:red", "data : " + this.$data); console.log("%c%s", "color:red", "message: " + this.message); }, beforeUpdate: function() { console.group("beforeUpdate 更新前状态===============》"); console.log("%c%s", "color:red", "el : " + this.$el); console.log(this.$el); console.log("%c%s", "color:red", "data : " + this.$data); console.log("%c%s", "color:red", "message: " + this.message); }, updated: function() { console.group("updated 更新完成状态===============》"); console.log("%c%s", "color:red", "el : " + this.$el); console.log(this.$el); console.log("%c%s", "color:red", "data : " + this.$data); console.log("%c%s", "color:red", "message: " + this.message); }, beforeDestroy: function() { console.group("beforeDestroy 销毁前状态===============》"); console.log("%c%s", "color:red", "el : " + this.$el); console.log(this.$el); console.log("%c%s", "color:red", "data : " + this.$data); console.log("%c%s", "color:red", "message: " + this.message); }, destroyed: function() { console.group("destroyed 销毁完成状态===============》"); console.log("%c%s", "color:red", "el : " + this.$el); console.log(this.$el); console.log("%c%s", "color:red", "data : " + this.$data); console.log("%c%s", "color:red", "message: " + this.message); } }).$mount("#app");
|