注意:
有时候使用npm i node-sass -D装不上,这时候,就必须使用 cnpm i node-sass -D
在普通页面中使用render函数渲染组件
在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规则:
1 |
|
- 创建
App.js组件页面:
1 |
|
- 创建
main.js入口文件:
1 |
|
在使用webpack构建的Vue项目中使用模板对象?
- 在
webpack.config.js中添加resolve属性:1
2
3
4
5resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
}
ES6中语法使用总结
使用
export default和export导出模块中的成员; 对应ES5中的module.exports和export使用
import ** from **和import '路径'还有import {a, b} from '模块标识'导入其他模块使用箭头函数:
(a, b)=> { return a-b; }
在vue组件页面中,集成vue-router路由模块
- 导入路由模块:
1 |
|
- 安装路由模块:
1 |
|
- 导入需要展示的组件:
1 |
|
- 创建路由对象:
1 |
|
- 将路由对象,挂载到 Vue 实例上:
1 |
|
- 改造App.vue组件,在 template 中,添加
router-link和router-view:
1 |
|
组件中的css作用域问题
抽离路由为单独的模块
使用 饿了么的 MintUI 组件
- 导入所有MintUI组件:
1 |
|
- 导入样式表:
1 |
|
- 在 vue 中使用 MintUI:
1 |
|
- 使用的例子:
1 |
|
使用 MUI 组件
- 导入 MUI 的样式表:
1 |
|
- 在
webpack.config.js中添加新的loader规则:
1 |
|
- 根据官方提供的文档和example,尝试使用相关的组件
将项目源码托管到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到仓储中
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
2
3
4
5
6
.router-link-active{
color:#007aff !important;
}- 或者在
new VueRouter的时候,通过linkActiveClass来指定高亮的类:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// 创建路由对象
var router = new VueRouter({
routes: [
{ path: '/', redirect: '/home' }
],
linkActiveClass: 'mui-active'
});
实现 tabbar 页签不同组件页面的切换
将 tabbar 改造成
router-link形式,并指定每个连接的to属性;在入口文件中导入需要展示的组件,并创建路由对象:
1 |
|
使用 mt-swipe 轮播图组件
- 假数据:
1 |
|
- 引入轮播图组件:
1 |
|
在.vue组件中使用vue-resource获取数据
运行
cnpm i vue-resource -S安装模块导入 vue-resource 组件
1 |
|
- 在vue中使用 vue-resource 组件
1 |
|