#升级Vue
##引入Vue
Vue升级2.0,将compiler与runtime 分开,分成两个build,分别是:
-Standalone build: includes both the compiler and the runtime. This functions basically exactly the same Vue 1.x does.
-Runtime only build:since it doesn’t include the compiler, you need to either pre-compiled templates in a compile step, or manually written render functions. The npm package will export this build by default, since when consuming Vue from npm, you will likely be using a compilation step (with Browserify or Webpack), during which vueif or vue-loader will perform the template pre-compilation.
默认引入Runtime only build,而我们在不想要改变过去的一系列构建模式的前提下,需要引入Standalone build,路径是’vue/dist/vue.js’(Runtime only build引入的实际上也是dist文件下的文件)
##生命周期钩子
一定要注意vue2.0对生命周期钩子函数的大量改动:
init -> beforeCreate
created
beforeDestroy
destroyed
beforeMount(new)
mounte(new)
beforeUpdate(new)
updated(new)
activated (new) (for keep-alive)
deactivated (new) (for keep-alive)
ready | deprecated, use mounted (there’s no longer the guarantee to be in-document)
activate | deprecated, moved into vue-router
beforeCompile | deprecated, use created
compiled | deprecated, use mounted
attached | deprecated, use custom in-dom check in other hooks
detached | deprecated, same as above
#升级vue-router
就我们目前的项目来说,问题主要出现在以下两点:
-router.map方法废弃,此类方法统一作为属性加入到构造函数中(见https://github.com/vuejs/vue-router/releases)。
-router.start方法废弃,没有在源码或者realease log中发现对应的替代实现。