vue 学习笔记第无弹
1. 在 webpack 中配置 .vue 组件页面的解析
运行
cnpm i vue -S
将 vue 安装为运行依赖;运行
cnpm i vue-loader vue-template-compiler -D
将解析转换 vue 的包安装为开发依赖;运行
cnpm i style-loader css-loader -D
将解析转换 CSS 的包安装为开发依赖,因为 .vue 文件中会写 CSS 样式;在
webpack.config.js
中,添加如下module
规则:
1module: {23 rules: [45 { test: /\.css$/, use: ['style-loader', 'css-loader'] },67 { test: /\.vue$/, use: 'vue-loader' }89 ]
10
11 }
创建
App.js
组件页面:
1 <template>23 <!-- 注意:在 .vue 的组件中,template 中必须有且只有唯一的根元素进行包裹,一般都用 div 当作唯一的根元素 -->45 <div>67 <h1>这是APP组件 - {{msg}}</h1>89 <h3>我是h3</h3>
10
11 </div>
12
13 </template>
14
15
16
17 <script>
18
19 // 注意:在 .vue 的组件中,通过 script 标签来定义组件的行为,需要使用 ES6 中提供的 export default 方式,导出一个vue实例对象
20
21 export default {
22
23 data() {
24
25 return {
26
27 msg: 'OK'
28
29 }
30
31 }
32
33 }
34
35 </script>
36
37
38
39 <style scoped>
40
41 h1 {
42
43 color: red;
44
45 }
46
47 </style>
创建
main.js
入口文件:
1 // 导入 Vue 组件23 import Vue from 'vue'4567 // 导入 App组件89 import App from './components/App.vue'
10
11
12
13 // 创建一个 Vue 实例,使用 render 函数,渲染指定的组件
14
15 var vm = new Vue({
16
17 el: '#app',
18
19 render: c => c(App)
20
21 });
2. 在使用 webpack 构建的 Vue 项目中使用模板对象?
在
webpack.config.js
中添加resolve
属性:
1resolve: {
2 alias: {
3 'vue$': 'vue/dist/vue.esm.js'
4 }
5 }
3. ES6中语法使用总结
使用
export default
和export
导出模块中的成员; 对应ES5中的module.exports
和export
使用
import ** from **
和import '路径'
还有import {a, b} from '模块标识'
导入其他模块使用箭头函数:
(a, b)=> { return a-b; }
4. 在 vue 组件页面中,集成 vue-router 路由模块
vue-router官网
导入路由模块:
1import VueRouter from 'vue-router'
安装路由模块:
1Vue.use(VueRouter);
导入需要展示的组件:
1import login from './components/account/login.vue'
2
3import register from './components/account/register.vue'
创建路由对象:
1var router = new VueRouter({23 routes: [45 { path: '/', redirect: '/login' },67 { path: '/login', component: login },89 { path: '/register', component: register }
10
11 ]
12
13});
将路由对象,挂载到 Vue 实例上:
1var vm = new Vue({23 el: '#app',45 // render: c => { return c(App) }67 render(c) {89 return c(App);
10
11 },
12
13 router // 将路由对象,挂载到 Vue 实例上
14
15});
改造App.vue组件,在 template 中,添加
router-link
和router-view
:
1 <router-link to="/login">登录</router-link>
2
3 <router-link to="/register">注册</router-link>
4
5
6
7 <router-view></router-view>
5. 使用 饿了么的 MintUI 组件
Github 仓储地址
Mint-UI官方文档
导入所有 MintUI 组件:
1import MintUI from 'mint-ui'
导入样式表:
1import 'mint-ui/lib/style.css'
在 vue 中使用 MintUI:
1Vue.use(MintUI)
使用的例子:
1<mt-button type="primary" size="large">primary</mt-button>
6. 使用 MUI 组件
官网首页
文档地址
导入 MUI 的样式表:
1import '../lib/mui/css/mui.min.css'
在
webpack.config.js
中添加新的loader规则:
1{ test: /\.(png|jpg|gif|ttf)$/, use: 'url-loader' }
根据官方提供的文档和example,尝试使用相关的组件
7. 将项目源码托管到 oschina 中
点击头像 -> 修改资料 -> SSH公钥 如何生成SSH公钥
创建自己的空仓储,使用
git config --global user.name "用户名"
和git config --global user.email ***@**.com
来全局配置提交时用户的名称和邮箱使用
git init
在本地初始化项目使用
touch README.md
和touch .gitignore
来创建项目的说明文件和忽略文件;使用
git add .
将所有文件托管到 git 中使用
git commit -m "init project"
将项目进行本地提交使用
git remote add origin 仓储地址
将本地项目和远程仓储连接,并使用origin最为远程仓储的别名使用
git push -u origin master
将本地代码 push 到仓储中
8. App.vue 组件的基本设置
头部的固定导航栏使用
Mint-UI
的Header
组件;底部的页签使用
mui
的tabbar
;购物车的图标,使用
icons-extra
中的mui-icon-extra mui-icon-extra-cart
,同时,应该把其依赖的字体图标文件mui-icons-extra.ttf
,复制到fonts
目录下!将底部的页签,改造成
router-link
来实现单页面的切换;Tab Bar 路由激活时候设置高亮的两种方式:
全局设置样式如下:
1 .router-link-active{ color:#007aff !important; 2}
或者在
new VueRouter
的时候,通过linkActiveClass
来指定高亮的类:1 // 创建路由对象23var router = new VueRouter({45 routes: [{ path: '/', redirect: '/home' }6 ],78 linkActiveClass: 'mui-active'9 10});
9. 实现 tabbar 页签不同组件页面的切换
将 tabbar 改造成
router-link
形式,并指定每个连接的to
属性;在入口文件中导入需要展示的组件,并创建路由对象:
1 // 导入需要展示的组件23 import Home from './components/home/home.vue'45 import Member from './components/member/member.vue'67 import Shopcar from './components/shopcar/shopcar.vue'89 import Search from './components/search/search.vue'
10
11
12
13 // 创建路由对象
14
15 var router = new VueRouter({
16
17 routes: [
18
19 { path: '/', redirect: '/home' },
20
21 { path: '/home', component: Home },
22
23 { path: '/member', component: Member },
24
25 { path: '/shopcar', component: Shopcar },
26
27 { path: '/search', component: Search }
28
29 ],
30
31 linkActiveClass: 'mui-active'
32
33 });
10. 使用 mt-swipe 轮播图组件
假数据:
1lunbo: [
2
3 'http://www.itcast.cn/images/slidead/BEIJING/2017440109442800.jpg',
4
5 'http://www.itcast.cn/images/slidead/BEIJING/2017511009514700.jpg',
6
7 'http://www.itcast.cn/images/slidead/BEIJING/2017421414422600.jpg'
8
9 ]
引入轮播图组件:
1<!-- Mint-UI 轮播图组件 -->23 <div class="home-swipe">45 <mt-swipe :auto="4000">67 <mt-swipe-item v-for="(item, i) in lunbo" :key="i">89 <img :src="item" alt="">
10
11 </mt-swipe-item>
12
13 </mt-swipe>
14
15 </div>
16
17 </div>
11. 在 .vue 组件中使用 vue-resource 获取数据
运行
cnpm i vue-resource -S
安装模块导入 vue-resource 组件
1import VueResource from 'vue-resource'
在vue中使用 vue-resource 组件
1Vue.use(VueResource);
往期精选
1. VUE 学习第一天
2. vue 学习笔记第二弹
3. vue 学习笔记第三弹
4. vue 学习笔记第四弹 - Webpack
不甘于「本该如此」,「多选参数 」值得关注
vue 学习笔记第无弹相关推荐
- Vue学习笔记进阶篇——Render函数
本文为转载,原文:Vue学习笔记进阶篇--Render函数 基础 Vue 推荐在绝大多数情况下使用 template 来创建你的 HTML.然而在一些场景中,你真的需要 JavaScript 的完全编 ...
- Vue学习笔记: Vue + Element-ui搭建后台管理系统模板
Vue学习笔记: Vue + Element-ui搭建后台管理系统模板 技术:Vue + Element-ui 功能:后台管理系统基础模板,路由配置,加载页面进度条,请求响应拦截器的封装等 页面预览: ...
- 狂神说 vue学习笔记
vue学习笔记 文章目录 vue学习笔记 一.第一个vue程序 1. 什么是MVVM 2. 为什么要使用MVVM 3.直接新建项目 4.导入vue.js 5.简单绑定元素 6 vue的声明周期 二.V ...
- 菜鸟Vue学习笔记(三)
菜鸟Vue学习笔记(三) 本周使用了Vue来操作表单,接下来说下Vue中双向绑定表单元素的用法. Vue中双向绑定是使用的v-model,所谓的双向绑定即改变变量的值,表单元素的值也会改变,同样的,改 ...
- Vue学习笔记入门篇——数据及DOM
本文为转载,原文:Vue学习笔记入门篇--数据及DOM 数据 data 类型 Object | Function 详细 Vue 实例的数据对象.Vue 将会递归将 data 的属性转换为 getter ...
- vue学习笔记-03-浅谈组件-概念,入门,如何用props给组件传值?
vue学习笔记-03-浅谈组件-概念,入门,如何用props给组件传值? 文章目录 vue学习笔记-03-浅谈组件-概念,入门,如何用props给组件传值? 什么是组件? 为什么要使用组件? 如何使用 ...
- vue学习笔记-02-前端的发展历史浅谈mmvm设计理念
vue学习笔记-02-前端的发展历史浅谈mmvm设计理念 文章目录 1. MVVM模式的实现者 2.第一个vue程序 3.什么是mvvm? 4.为什么要用mvvm? 5.mvvm的组成部分 7.MVV ...
- vue学习笔记-01-前端的发展历史(从后端到前端,再到前后端分离,再到全栈)
vue学习笔记-01-前端的发展历史(从后端到前端,再到前后端分离,再到全栈) 这篇文章是博主在看vue-前端发展简史的时候做的笔记,以供后续学习复习 文章目录 vue学习笔记-01-前端的发展历 ...
- vue学习笔记之:为何data是一个方法
vue学习笔记之:为何data是一个方法 在vue开发中,我们可以发现,data中的属性值是在function中return出来的.可为何data必须是一个函数呢?我们先看官方的解释: 当一个组件被定 ...
最新文章
- 开头轰轰烈烈,结局冷冷清清
- 使用 Pandas、Jinja 和 WeasyPrint,轻松创建一个 PDF 报表
- AutoML前沿技术与实践经验分享 | 免费报名
- 如何使用资源和样式调整控件外观
- 乐高ev3搭建图_乐高EV3作品|机械夹子(二)
- pdfbox 第一页加内容_你用代码做过哪些很酷/有趣的事?
- 收不回来的value
- js 通用 保留两位小数 金额千分位格式化
- weblogic启动项目失败查看_weblogic启动报错常见错误解决办法
- 【Java编码规范】《阿里巴巴Java开发手册(正式版)》
- 【网络安全】加解密算法最详解
- 有效管理“刺头”员工的方法
- 苹果软件上app注意事项
- uva 10306 简单DP
- 使用vs2008制作dll文件,生成动态链接库
- 深入浅出理解数据分析系列之:Python安装Excel文档库openpyxl和Pycharm为项目安装Excel文档库openpyxl
- Vertica资源池
- 一个通用的ajax程序(实现像百度一样自动提示功能)
- html向下的三角符号怎么打,哪些字符可用于上/下三角形(无茎的箭头)以HTML显示?...
- 用python爬取斗图啦图片