Vue如何新建一个项目

Vue如何新建一个项目

  • 环境: Centos7.X

node 安装(略)

使用淘宝NPM 镜像

npm  install  -g  cnpm  --registry=https://registry.npm.taobao.org

安装 vue-cli

cnpm install vue-cli -g      //全局安装 vue-cli
(test001) [root@k3s-master test001]# vue -V && vue list 
2.9.6

  Available official templates:

    browserify - A full-featured Browserify + vueify setup with hot-reload, linting & unit testing.
    browserify-simple - A simple Browserify + vueify setup for quick prototyping.
    pwa - PWA template for vue-cli based on the webpack template
    simple - The simplest possible Vue setup in a single HTML file
    webpack - A full-featured Webpack + vue-loader setup with hot reload, linting, testing & css extraction.
    webpack-simple - A simple Webpack + vue-loader setup for quick prototyping.

创建项目

(test001) [root@k3s-master test001]# vue init webpack vue-html

? Project name vue-html
? Project description A Vue.js project
? Author helmchars <1392514847@qq.com>
? Vue build standalone
? Install vue-router? Yes
? Use ESLint to lint your code? No
? Set up unit tests No
? Setup e2e tests with Nightwatch? No
? Should we run `npm install` for you after the project has been created? (recommended) npm

   vue-cli · Generated "vue-html".
# Installing project dependencies ...
# ========================
npm xxxxxxxxxxxxxxx


  cd vue-html
  npm run dev
Documentation can be found at https://vuejs-templates.github.io/webpack

修改启动端口和IP

# webpack 中 npm run dev 不能通过ip访问 只能通过localhost访问
# 修改vue-cli: config/index.js 文件, 把文件中 host 的值,改成 ip 即可

host: 'localhost'   ==>  host: '0.0.0.0'

测试

  • 浏览器访问: http://ip:8080

vue3

卸载系统残留 2 版本

(test001) [root@k3s-master test001]# vue create vue-html

  vue create is a Vue CLI 3 only command and you are using Vue CLI 2.9.6.
  You may want to run the following to upgrade to Vue CLI 3:

  npm uninstall -g vue-cli
  npm install -g @vue/cli

创建项目

vue create  vue-html

启动项目

cd vue-html
npm run server


 DONE  Compiled successfully in 158ms                                                                                             6:32:46 PM


  App running at:
  - Local:   http://localhost:8080/ 
  - Network: http://10.11.9.246:8080/

Last updated