第一个VUE-Demo项目

第一个VUE项目

原文链接:https://www.runoob.com/vue2/vue-install.html

  1. 安装vue-cli
# 全局安装 vue-cli
$ cnpm install --global vue-cli
# 创建一个基于 webpack 模板的新项目
$ vue init webpack my-project
# 这里需要进行一些配置,默认回车即可
This will install Vue 2.x version of the template.

For Vue 1.x use: vue init webpack#1.0 my-project

? Project name my-project
? Project description A Vue.js project
? Author runoob <test@runoob.com>
? Vue build standalone
? Use ESLint to lint your code? Yes
? Pick an ESLint preset Standard
? Setup unit tests with Karma + Mocha? Yes
? Setup e2e tests with Nightwatch? Yes

   vue-cli · Generated "my-project".

   To get started:

     cd my-project
     npm install
     npm run dev

   Documentation can be found at https://vuejs-templates.github.io/webpack
  1. 进入项目,安装并运行
$ cd my-project
$ cnpm install
$ cnpm run dev
 DONE  Compiled successfully in 4388ms

> Listening at http://localhost:8080

成功执行以上命令后访问 http://localhost:8080/,输出结果如下所示:

启动成功后的Vue访问界面

注意:Vue.js 不支持 IE8 及其以下 IE 版本。

  1. Vue 项目打包

打包 Vue 项目使用以下命令:

npm run build

执行完成后,会在 Vue 项目下生成一个 dist 目录,一般包含 index.html 文件及 static 目录,static 目录包含了静态文件 js、css 以及图片目录 images。

打包完成的图片

如果直接双击 index.html 打开浏览器,页面可能是空白了,想要修改下 index.html 文件中 js、css 路径即可。
例如我们打开 dist/index.html 文件看到路径是绝对路径:

<link href=/static/css/app.33da80d69744798940b135da93bc7b98.css rel=stylesheet>
<script type=text/javascript src=/static/js/app.717bb358ddc19e181140.js></script>

我们把 js、css 路径路径修改为相对路径:

<link href=static/css/app.33da80d69744798940b135da93bc7b98.css rel=stylesheet>
<script type=text/javascript src=static/js/app.717bb358ddc19e181140.js></script>

这样直接双击 dist/index.html 文件就可以在浏览器中看到效果了。

posted @ 2022-06-06 14:54  我见青山应如是  阅读(188)  评论(0编辑  收藏  举报