手写vue-router
hash模式 :location.hash: 获取url的hash值; window.onhashchange监听hash的改变 history模式 :location.pathname:获取路径; window.onpopstate监听history变化 vue.use的用法 : 把你给它的东西调用一遍;如果你给它的是一个方法,那么它会直接执行这个方法,如果你给它的东西里有一个install属性,它会执行这个install function a () { console.log('This is function a') } a.install = function (vue) { console.log('add "install" property to function a') // 全局混入vue实例,添加在mixin中的的变量,方法在所有子组件中都可以被获取到 vue.mixin({ data () { return { c: 'this is in mixin' } }, methods: { testMethod () { } }, // 生命周期注入 created () { console.log('I\'m in global created method') } }) } Vue.use(a) // add "install" property to