vue1.0升级到2.0并不是什么难事,它主要就是对vuejs的api做的一些变更,那么升级到2.0要怎么做呢?
首先,1.0和2.0它的脚手架有什么区别,它的区别主要就是配置文件的更改,
配置文件修改包括以下文件:
1.Package.json文件修改 2.Build目录修改 3.Config目录修改
如下图所示的项目目录:
上图就是项目源码的目录,那我们用脚手架安装1.0和2.0项目,它们最大的区别主要就是:(1)build目录下面的配置文件(2)config目录下面的配置文件(3)package.json依赖包(它们两个依赖的东西会有区别)
package.json升级
1.0-version
{
"name": "sell",
"version": "1.0.0",
"description": "sell app",
"author": "ustbhuangyi <280309453@qq.com>",
"private": true,
"scripts": {
"dev": "node build/dev-server.js",
"build": "node build/build.js",
"test": "",
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"
},
"dependencies": {
"vue": "^1.0.21",
"vue-router": "^0.7.13",
"vue-resource": "^1.0.1",
"babel-runtime": "^6.0.0",
"better-scroll": "^0.1.7"
},
"devDependencies": {
"babel-core": "^6.0.0",
"babel-eslint": "^6.1.2",
"babel-loader": "^6.0.0",
"babel-plugin-transform-runtime": "^6.0.0",
"babel-preset-es2015": "^6.0.0",
"babel-preset-stage-2": "^6.0.0",
"babel-register": "^6.0.0",
"connect-history-api-fallback": "^1.1.0",
"css-loader": "^0.23.0",
"stylus-loader": "^2.1.1",
"eslint": "^2.10.2",
"eslint-friendly-formatter": "^2.0.5",
"eslint-loader": "^1.3.0",
"eslint-plugin-html": "^1.3.0",
"eslint-config-standard": "^5.1.0",
"eslint-plugin-promise": "^1.0.8",
"eslint-plugin-standard": "^1.3.2",
"eventsource-polyfill": "^0.9.6",
"express": "^4.13.3",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.8.4",
"function-bind": "^1.0.2",
"html-webpack-plugin": "^2.8.1",
"http-proxy-middleware": "^0.12.0",
"json-loader": "^0.5.4",
"ora": "^0.2.0",
"shelljs": "^0.6.0",
"url-loader": "^0.5.7",
"vue-hot-reload-api": "^1.2.0",
"vue-html-loader": "^1.0.0",
"vue-loader": "^8.3.0",
"vue-style-loader": "^1.0.0",
"webpack": "^1.12.2",
"webpack-dev-middleware": "^1.4.0",
"webpack-hot-middleware": "^2.6.0",
"webpack-merge": "^0.8.3"
}
}
2.0-version
{
"name": "sell",
"version": "1.0.0",
"description": "sell app",
"author": "ustbhuangyi <280309453@qq.com>",
"private": true,
"scripts": {
"dev": "node build/dev-server.js",
"build": "node build/build.js",
"test": "",
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"
},
"keywords": [
"vue",
"vue-sell",
"webapp"
],
"dependencies": {
"vue": "^2.2.1",
"vue-resource": "1.0.3",
"vue-router": "^2.2.0",
"babel-runtime": "^6.0.0",
"better-scroll": "^0.1.11"
},
"devDependencies": {
"autoprefixer": "^6.4.0",
"babel-core": "^6.0.0",
"babel-eslint": "^7.0.0",
"babel-loader": "^6.0.0",
"babel-plugin-transform-runtime": "^6.0.0",
"babel-preset-es2015": "^6.0.0",
"babel-preset-stage-2": "^6.0.0",
"babel-register": "^6.0.0",
"chalk": "^1.1.3",
"connect-history-api-fallback": "^1.1.0",
"css-loader": "^0.25.0",
"eslint": "^3.7.1",
"eslint-friendly-formatter": "^2.0.5",
"eslint-loader": "^1.5.0",
"eslint-plugin-html": "^1.3.0",
"eslint-config-standard": "^6.1.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1",
"eventsource-polyfill": "^0.9.6",
"express": "^4.13.3",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.9.0",
"friendly-errors-webpack-plugin": "^1.1.2",
"function-bind": "^1.0.2",
"html-webpack-plugin": "^2.8.1",
"http-proxy-middleware": "^0.17.2",
"json-loader": "^0.5.4",
"semver": "^5.3.0",
"opn": "^4.0.2",
"ora": "^0.3.0",
"shelljs": "^0.7.4",
"url-loader": "^0.5.7",
"vue-loader": "^11.1.4",
"vue-style-loader": "^2.0.0",
"stylus": "^0.54.5",
"stylus-loader": "^2.1.1",
"vue-template-compiler": "^2.2.1",
"webpack": "^1.13.2",
"webpack-dev-middleware": "^1.8.3",
"webpack-hot-middleware": "^2.12.2",
"webpack-merge": "^0.14.1"
},
"engines": {
"node": ">= 4.0.0",
"npm": ">= 3.0.0"
}
}
我们从两个版本的package.json
中可以看到,dependencies
字段中的vue从^1.0.21
升级到^2.2.1
,vue-router
从^0.7.13
升级到^2.2.0
。有些人,在项目中,vue用的是2.0,但是router
用的是1.0,所以会报一些错误,这时候需要对router进行相应的升级。也可以看到2.0的dependencies
和1.0的dependencies
也是有区别的,那我们怎么改呢?很简单,我们可以用2.0的脚手架去初始化一个项目,把2.0里面的package.json
中的依赖拷贝到1.0项目下的package.json
中,覆盖了,然后再去执行一次npm install
,就ok啦。这里讲的只是对vue
和vue-router
版本的升级,仅仅是是举个例子,在实际项目中,根据自己项目依赖的不同,会升级一些不同的依赖。
Build目录和Config目录
这两个目录主要就是把2.0里面的Build
目录和Config
目录拷贝到1.0里面,把1.0的覆盖了,当然覆盖的时候一定要注意你之前自己在1.0项目过程中的一些配置代码,也要把那些代码写到2.0里面去,这样就可以了。
重要的注释:
首先,上面的只是告诉你把vue和vue-router进行版本升级,但是版本升级了,那么代码肯定会有出入,肯定需要对1.0的vue代码进行部分修改,以适应2.0的vue。那么,你需要在当前项目下运行迁移工具(vue-migration-helper
)。我们非常谨慎地把高级 Vue 升级过程简化为使用一个简单的命令行工具。当工具识别出旧有的特性后,就会告知你并给出建议,同时附上关于详细信息的链接,如下图所示。
具体的迁移方法,请参照https://cn.vuejs.org/v2/guide...
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。