小白教程
所有教程
关于
Search
172.70.38.7
172.70.38.7
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Vue3 安装”的源代码
本页内容
上一节:
Vue3_教程
下一节:
Vue3_打包
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:Vue3 安装}}[[Category:Vue 3 教程|2]] = Vue3 安装 = == 1、独立版本 == 我们可以在 Vue.js 的官网上直接下载最新版本, 并用 '''<script>''' 标签引入。 [https://unpkg.com/vue@next 下载 Vue.js] == 2、使用 CDN 方法 == 以下推荐国外比较稳定的两个 CDN,国内还没发现哪一家比较好,目前还是建议下载到本地。 * '''Staticfile CDN(国内)''' : https://cdn.staticfile.org/vue/3.0.5/vue.global.js * '''unpkg''':https://unpkg.com/vue@next, 会保持和 npm 发布的最新的版本一致。 * '''cdnjs''' : https://cdnjs.cloudflare.com/ajax/libs/vue/3.0.5/vue.global.js * '''字节CDN''': https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/3.2.31/vue.global.min.js == Staticfile CDN(国内) == <sample title="" desc="" lang="html" hererun="1"> <div id="app"> <p>{{ message }}</p> </div> </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Vue 测试实例 - 小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/vue/3.0.5/vue.global.js"></script> </head> <body> <div id="hello-vue" class="demo"> {{ message }} </div> <script> const HelloVueApp = { data() { return { message: 'Hello Vue!!' } } } Vue.createApp(HelloVueApp).mount('#hello-vue') </script> </body> </html> </run> == unpkg(推荐) == <sample title="" desc="" lang="html" hererun="1"> <div id="app"> <p>{{ message }}</p> </div> </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Vue 测试实例 - 小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/vue/3.2.36/vue.global.min.js"></script> </head> <body> <div id="hello-vue" class="demo"> {{ message }} </div> <script> const HelloVueApp = { data() { return { message: 'Hello Vue!!' } } } Vue.createApp(HelloVueApp).mount('#hello-vue') </script> </body> </html> </run> == cdnjs == <sample title="" desc="" lang="html" hererun="1"> <div id="app"> <p>{{ message }}</p> </div> </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Vue 测试实例 - 小白教程(xiaobai.wang)</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/3.0.5/vue.global.js"></script> </head> <body> <div id="hello-vue" class="demo"> {{ message }} </div> <script> const HelloVueApp = { data() { return { message: 'Hello Vue!!' } } } Vue.createApp(HelloVueApp).mount('#hello-vue') </script> </body> </html> </run> == 3、NPM 方法 == 由于 npm 安装速度慢,本教程使用了淘宝的镜像及其命令 cnpm,安装使用介绍参照:[[nodejs npm#taobaonpm|使用淘宝 NPM 镜像]]。 npm 版本需要大于 3.0,如果低于此版本需要升级它: <pre> # 查看版本 $ npm -v 2.3.0 #升级 npm cnpm install npm -g # 升级或安装 cnpm npm install cnpm -g </pre> 在用 Vue.js 构建大型应用时推荐使用 cnpm 安装,cnpm 能很好地和 Webpack 或 Browserify 模块打包器配合使用: <pre> # 最新稳定版 $ cnpm install vue@next </pre> == 命令行工具 == Vue.js 提供一个官方命令行工具,可用于快速搭建大型单页应用。 对于 Vue 3,你应该使用 npm 上可用的 Vue CLI v4.5 作为 @vue/cli。要升级,你应该需要全局重新安装最新版本的 @vue/cli: <pre># 全局安装 vue-cli yarn global add @vue/cli # 或 cnpm install -g @vue/cli</pre> 安装完后查看版本: <pre> $ vue --version @vue/cli 4.5.11 </pre> 然后在 Vue 项目中运行: <pre>vue upgrade --next</pre> '''注意:'''vue-cli 3.x 和 vue-cli 2.x 使用了相同的 vue 命令,如果你之前已经安装了 vue-cli 2.x,它会被替换为 Vue-cli 3.x。 === 创建项目 === 以下实例我们使用 vue init 命令来创建一个项目: <pre> $ vue init webpack xiaobai-vue3-test # 这里需要进行一些配置,默认回车即可 ? Project name xiaobai-vue3-test ? Project description A Vue.js project ? Author xiaobai <test@xiaobai.wang> ? Vue build standalone ? Install vue-router? Yes ? Use ESLint to lint your code? Yes ? Pick an ESLint preset Standard ? Set up unit tests Yes ? Pick a test runner jest ? Setup e2e tests with Nightwatch? Yes ? Should we run `npm install` for you after the project has been created? (recommended) npm vue-cli · Generated "xiaobai-vue3-test". # Installing project dependencies ... # ======================== ... </pre> 进入项目,安装并运行: <pre> $ cd xiaobai-vue3-test $ cnpm run dev DONE Compiled successfully in 2558ms I Your application is running here: http://localhost:8080 </pre> 成功执行以上命令后访问 http://localhost:8080/,输出结果如下所示: <blockquote>'''注意:'''Vue.js 不支持 IE8 及其以下 IE 版本。 </blockquote> == Vite (推荐) == Vite 是一个 web 开发构建工具,由于其原生 ES 模块导入方式,可以实现闪电般的冷服务器启动。 通过在终端中运行以下命令,可以使用 Vite 快速构建 Vue 项目,语法格式如下: <pre>npm init @vitejs/app <project-name></pre> 创建项目 xiaobai-vue3-test2: <pre>$ cnpm init @vitejs/app xiaobai-vue3-test2</pre> 运行项目: <pre>$ cd xiaobai-vue3-test2 $ cnpm install $ cnpm run dev > xiaobai-vue3-test2@0.0.0 dev /Users/tianqixin/xiaobai-test/vue3/xiaobai-vue3-test2 > vite [vite] Optimizable dependencies detected: vue Dev server running at: > Local: http://localhost:3000/</pre> 打开 '''http://localhost:3000/''',显示如下:
返回至“
Vue3 安装
”。
上一节:
Vue3_教程
下一节:
Vue3_打包