跟我一起做一个vue的小项目(一)

本文详细介绍使用Vue CLI创建移动端项目的过程,包括环境配置、页面路由设置、解决一像素问题及点击延迟,同时引入FastClick和Stylus提升用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目架子

npm install --global vue-cli
vue init webpack travel
cd travel/
npm run dev

运行效果
1037363-20190630203308574-476924557.png
添加home页及其路由,添加list页及其路由
1037363-20190630214600206-1816579687.png
1037363-20190630214609689-1986741262.png
1037363-20190630214722245-175207399.png
1037363-20190701000948746-1725621868.png
移动端项目配置项完善

<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">

解决一像素问题

//border.css
@charset "utf-8";
.border,
.border-top,
.border-right,
.border-bottom,
.border-left,
.border-topbottom,
.border-rightleft,
.border-topleft,
.border-rightbottom,
.border-topright,
.border-bottomleft {
    position: relative;
}
.border::before,
.border-top::before,
.border-right::before,
.border-bottom::before,
.border-left::before,
.border-topbottom::before,
.border-topbottom::after,
.border-rightleft::before,
.border-rightleft::after,
.border-topleft::before,
.border-topleft::after,
.border-rightbottom::before,
.border-rightbottom::after,
.border-topright::before,
.border-topright::after,
.border-bottomleft::before,
.border-bottomleft::after {
    content: "\0020";
    overflow: hidden;
    position: absolute;
}
/* border
 * 因,边框是由伪元素区域遮盖在父级
 * 故,子级若有交互,需要对子级设置
 * 定位 及 z轴
 */
.border::before {
    box-sizing: border-box;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    border: 1px solid #eaeaea;
    transform-origin: 0 0;
}
.border-top::before,
.border-bottom::before,
.border-topbottom::before,
.border-topbottom::after,
.border-topleft::before,
.border-rightbottom::after,
.border-topright::before,
.border-bottomleft::before {
    left: 0;
    width: 100%;
    height: 1px;
}
.border-right::before,
.border-left::before,
.border-rightleft::before,
.border-rightleft::after,
.border-topleft::after,
.border-rightbottom::before,
.border-topright::after,
.border-bottomleft::after {
    top: 0;
    width: 1px;
    height: 100%;
}
.border-top::before,
.border-topbottom::before,
.border-topleft::before,
.border-topright::before {
    border-top: 1px solid #eaeaea;
    transform-origin: 0 0;
}
.border-right::before,
.border-rightbottom::before,
.border-rightleft::before,
.border-topright::after {
    border-right: 1px solid #eaeaea;
    transform-origin: 100% 0;
}
.border-bottom::before,
.border-topbottom::after,
.border-rightbottom::after,
.border-bottomleft::before {
    border-bottom: 1px solid #eaeaea;
    transform-origin: 0 100%;
}
.border-left::before,
.border-topleft::after,
.border-rightleft::after,
.border-bottomleft::after {
    border-left: 1px solid #eaeaea;
    transform-origin: 0 0;
}
.border-top::before,
.border-topbottom::before,
.border-topleft::before,
.border-topright::before {
    top: 0;
}
.border-right::before,
.border-rightleft::after,
.border-rightbottom::before,
.border-topright::after {
    right: 0;
}
.border-bottom::before,
.border-topbottom::after,
.border-rightbottom::after,
.border-bottomleft::after {
    bottom: 0;
}
.border-left::before,
.border-rightleft::before,
.border-topleft::after,
.border-bottomleft::before {
    left: 0;
}
@media (max--moz-device-pixel-ratio: 1.49), (-webkit-max-device-pixel-ratio: 1.49), (max-device-pixel-ratio: 1.49), (max-resolution: 143dpi), (max-resolution: 1.49dppx) {
    /* 默认值,无需重置 */
}
@media (min--moz-device-pixel-ratio: 1.5) and (max--moz-device-pixel-ratio: 2.49), (-webkit-min-device-pixel-ratio: 1.5) and (-webkit-max-device-pixel-ratio: 2.49), (min-device-pixel-ratio: 1.5) and (max-device-pixel-ratio: 2.49), (min-resolution: 144dpi) and (max-resolution: 239dpi), (min-resolution: 1.5dppx) and (max-resolution: 2.49dppx) {
    .border::before {
        width: 200%;
        height: 200%;
        transform: scale(.5);
    }
    .border-top::before,
    .border-bottom::before,
    .border-topbottom::before,
    .border-topbottom::after,
    .border-topleft::before,
    .border-rightbottom::after,
    .border-topright::before,
    .border-bottomleft::before {
        transform: scaleY(.5);
    }
    .border-right::before,
    .border-left::before,
    .border-rightleft::before,
    .border-rightleft::after,
    .border-topleft::after,
    .border-rightbottom::before,
    .border-topright::after,
    .border-bottomleft::after {
        transform: scaleX(.5);
    }
}
@media (min--moz-device-pixel-ratio: 2.5), (-webkit-min-device-pixel-ratio: 2.5), (min-device-pixel-ratio: 2.5), (min-resolution: 240dpi), (min-resolution: 2.5dppx) {
    .border::before {
        width: 300%;
        height: 300%;
        transform: scale(.33333);
    }
    .border-top::before,
    .border-bottom::before,
    .border-topbottom::before,
    .border-topbottom::after,
    .border-topleft::before,
    .border-rightbottom::after,
    .border-topright::before,
    .border-bottomleft::before {
        transform: scaleY(.33333);
    }
    .border-right::before,
    .border-left::before,
    .border-rightleft::before,
    .border-rightleft::after,
    .border-topleft::after,
    .border-rightbottom::before,
    .border-topright::after,
    .border-bottomleft::after {
        transform: scaleX(.33333);
    }
}
 //移动端30秒点击延迟问题 
npm install fastclick --save
//在main.js中添加
FastClick.attach(document.body)

1037363-20190701003641466-2133665317.png
安装stylus

npm install stylus --save
npm install stylus-loader --save

未完,待续。。。

转载于:https://www.cnblogs.com/smart-girl/p/11111980.html

<think>我们正在回答用户关于如何创建Vue 2项目的命令问题。根据引用内容,创建Vue 2项目有两种方式:使用Vue CLI 2.x 或 Vue CLI 3.x(或更高版本)来初始化项目。但是注意,Vue CLI 3.x虽然是为Vue 3设计的,但它也支持创建Vue 2项目。 引用[1]提到: - 使用Vue CLI 2.x初始化项目:需要全局安装vue-cli(即`npm install -g vue-cli`) - 使用Vue CLI 3.x初始化项目:需要全局安装@vue/cli(即`npm install -g @vue/cli`) 然而,Vue CLI 3及以上版本已经将Vue 2项目创建集成在起,我们可以通过选择Vue 2的预设来创建项目。另外,Vue CLI 2.x的初始化命令是`vue init`,而Vue CLI 3.x的初始化命令是`vue create`。 因此,创建Vue 2项目有两种方法: 方法1:使用Vue CLI 2.x(旧版) 步骤1:安装Vue CLI 2.x npm install -g vue-cli 步骤2:初始化项目(使用webpack模板) vue init webpack my-project 方法2:使用Vue CLI 3.x(或更高版本) 步骤1:安装Vue CLI npm install -g @vue/cli 步骤2:创建项目(在交互式命令行中选择Vue 2) vue create my-project 或者,在Vue CLI 3.x中,你也可以使用旧版的`vue init`命令来创建Vue 2项目(需要先全局安装一个桥接工具): npm install -g @vue/cli-init vue init webpack my-project 由于用户明确要创建Vue 2项目,并且可能希望使用Vue CLI 2.x的模板(如引用[2]和引用[3]中所示的代码结构),我们推荐两种方法,但要注意Vue CLI 2.x的模板已经不再更新,而Vue CLI 3.x提供了更现代化的配置。 因此,我们给出两种方法的命令: 方法Vue CLI 2.x): 1. 全局安装Vue CLI 2.x: ```bash npm install -g vue-cli ``` 2. 使用webpack模板初始化项目(这个模板会生成一个包含webpack配置的Vue2项目): ```bash vue init webpack my-project ``` 方法二(Vue CLI 3.x及以上): 1. 全局安装Vue CLI: ```bash npm install -g @vue/cli ``` 2. 创建项目(在交互式菜单中选择Vue2): ```bash vue create my-project ``` 然后,在交互式界面中,选择“Manually select features”,然后可以选择需要的特性(如Babel、Router、Vuex等),并在选择Vue版本时选择2.x。 或者,为了使用Vue CLI 3.x来模拟Vue CLI 2.x的webpack模板,可以安装桥接工具: 1. 全局安装Vue CLI和桥接工具: ```bash npm install -g @vue/cli npm install -g @vue/cli-init ``` 2. 使用以下命令创建项目(与Vue CLI 2.x相同): ```bash vue init webpack my-project ``` 注意:在Vue CLI 3.x中,使用`vue create`创建项目时,如果希望使用Vue 2,需要在选择版本时手动选择。 根据用户提供的引用内容,引用[2]和引用[3]中的代码结构是Vue CLI 2.x的webpack模板生成的,所以如果用户想要那样的结构,可以使用方法或者方法二中的桥接工具方式。 因此,我们给出完整的命令步骤: 推荐方法(使用桥接工具,既可以享受Vue CLI 3的环境,又可以使用旧模板): ```bash # 安装Vue CLI npm install -g @vue/cli # 安装桥接工具,使vue init命令可用 npm install -g @vue/cli-init # 创建Vue2项目(使用webpack模板) vue init webpack my-project ``` 或者,如果用户只想用Vue CLI 2.x(注意:Vue CLI 2.x已经停止维护): ```bash npm install -g vue-cli vue init webpack my-project ``` 或者,使用Vue CLI 3的默认创建方式(选择Vue2): ```bash npm install -g @vue/cli vue create my-project # 然后按照提示操作,选择Vue 2 ``` 在回答中,我们应当明确指出这些方法,并推荐使用桥接工具的方式,因为Vue CLI 2.x已经不再维护,而桥接工具允许使用旧模板但运行在新CLI上。 最后,我们按照要生成相关问题。</think>### 创建 Vue 2 项目的完整命令指南 #### 方法:使用 Vue CLI 2.x(经典方式) 1. **全局安装 Vue CLI 2.x**: ```bash npm install -g vue-cli ``` 2. **初始化 Vue 2 项目**: ```bash vue init webpack my-project ``` - 在交互式命令行中选择配置: ``` ? Project name (my-project) ? Project description (A Vue.js project) ? Author (your-name <your-email>) ? Vue build (Runtime + Compiler) ? Install vue-router? (Yes) # 推荐选择 ? Use ESLint? (Yes) # 按需选择 ? Pick an ESLint preset (Standard) ? Set up unit tests (No) # 按需选择 ? Setup e2e tests with Nightwatch? (No) ? Should we run `npm install`? (Yes) ``` - 项目结构将包含 `src/App.vue` 和 `src/main.js`(如引用[2]所示)[^2] #### 方法二:使用 Vue CLI 3/4/5(推荐方式) 1. **全局安装最新 Vue CLI**: ```bash npm install -g @vue/cli ``` 2. **创建项目并指定 Vue 2**: ```bash vue create my-project ``` - 在交互菜单中选择: ``` Please pick a preset: Manually select features ? Check features needed: Babel, Router, Vuex, Linter ? Choose Vue version: 2.x ? Use history mode? (Y/n) ? Pick a linter: ESLint with standard config ? Where to place config? In dedicated config files ``` #### 项目启动命令 ```bash cd my-project npm run dev # 启动开发服务器 ``` #### 文件结构说明 - `src/App.vue`:主组件模板(如引用[3]所示)[^3] - `src/main.js`:入口文件(如引用[2]所示)[^2] - `src/components/`:存放子组件 - `public/index.html`:主HTML模板 > **关键提示**: > 1. Vue CLI 2.x 直接生成传统Webpack配置(适合深度定制) > 2. Vue CLI 3+ 使用零配置脚手架(内置优化,推荐新项目)[^1] > 3. 两种方式都支持Vue 2开发,选择取决于项目
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值