有时候使用npm i node-sass -D
装不上,这时候,就必须使用 cnpm i node-sass -D
css
运行cnpm i vue -S
将vue安装为运行依赖;vue
运行cnpm i vue-loader vue-template-compiler -D
将解析转换vue的包安装为开发依赖;node
运行cnpm i style-loader css-loader -D
将解析转换CSS的包安装为开发依赖,由于.vue文件中会写CSS样式;webpack
在webpack.config.js
中,添加以下module
规则:git
module: {
rules: [
{ test: /\.css$/, use: ['style-loader', 'css-loader'] },
{ test: /\.vue$/, use: 'vue-loader' }
]
}
建立App.js
组件页面:github
<template>
<!-- 注意:在 .vue 的组件中,template 中必须有且只有惟一的根元素进行包裹,通常都用 div 看成惟一的根元素 -->
<div>
<h1>这是APP组件 - {{msg}}</h1>
<h3>我是h3</h3>
</div>
</template>
<script>
// 注意:在 .vue 的组件中,经过 script 标签来定义组件的行为,须要使用 ES6 中提供的 export default 方式,导出一个vue实例对象
export default {
data() {
return {
msg: 'OK'
}
}
}
</script>
<style scoped>
h1 {
color: red;
}
</style>
建立main.js
入口文件:web
// 导入 Vue 组件
import Vue from 'vue'
// 导入 App组件
import App from './components/App.vue'
// 建立一个 Vue 实例,使用 render 函数,渲染指定的组件
var vm = new Vue({
el: '#app',
render: c => c(App)
});
在webpack.config.js
中添加resolve
属性:vue-router
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
}
使用 export default
和 export
导出模块中的成员; 对应ES5中的 module.exports
和 export
npm
使用 import ** from **
和 import '路径'
还有 import {a, b} from '模块标识'
导入其余模块sass
使用箭头函数:(a, b)=> { return a-b; }
导入路由模块:
import VueRouter from 'vue-router'
安装路由模块:
Vue.use(VueRouter);
导入须要展现的组件:
import login from './components/account/login.vue'
import register from './components/account/register.vue'
建立路由对象:
var router = new VueRouter({
routes: [
{ path: '/', redirect: '/login' },
{ path: '/login', component: login },
{ path: '/register', component: register }
]
});
将路由对象,挂载到 Vue 实例上:
var vm = new Vue({
el: '#app',
// render: c => { return c(App) }
render(c) {
return c(App);
},
router // 将路由对象,挂载到 Vue 实例上
});
改造App.vue组件,在 template 中,添加router-link
和router-view
:
<router-link to="/login">登陆</router-link>
<router-link to="/register">注册</router-link>
<router-view></router-view>
样式的scoped是经过css的属性选择器实现的
<style scoped>
div{
color:red;
}
</style>
导入全部MintUI组件:
import MintUI from 'mint-ui'
导入样式表:
import 'mint-ui/lib/style.css'
在 vue 中使用 MintUI:
Vue.use(MintUI)
使用的例子:
<mt-button type="primary" size="large">primary</mt-button>
官网首页不能使用npm下载,须要手动从GitHub下载
导入 MUI 的样式表:
import '../lib/mui/css/mui.min.css'
在webpack.config.js
中添加新的loader规则:
{ test: /\.(png|jpg|gif|ttf)$/, use: 'url-loader' }
根据官方提供的文档和example,尝试使用相关的组件
点击头像 -> 修改资料 -> 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到仓储中
头部的固定导航栏使用 Mint-UI
的 Header
组件;
底部的页签使用 mui
的 tabbar
;
购物车的图标,使用 icons-extra
中的 mui-icon-extra mui-icon-extra-cart
,同时,应该把其依赖的字体图标文件 mui-icons-extra.ttf
,复制到 fonts
目录下!
将底部的页签,改形成 router-link
来实现单页面的切换;
Tab Bar 路由激活时候设置高亮的两种方式:
全局设置样式以下:
.router-link-active{
color:#007aff !important;
}
或者在 new VueRouter
的时候,经过 linkActiveClass
来指定高亮的类:
// 建立路由对象
var router = new VueRouter({
routes: [
{ path: '/', redirect: '/home' }
],
linkActiveClass: 'mui-active'
});
将 tabbar 改形成 router-link
形式,并指定每一个链接的 to
属性;
在入口文件中导入须要展现的组件,并建立路由对象:
// 导入须要展现的组件
import Home from './components/home/home.vue'
import Member from './components/member/member.vue'
import Shopcar from './components/shopcar/shopcar.vue'
import Search from './components/search/search.vue'
// 建立路由对象
var router = new VueRouter({
routes: [
{ path: '/', redirect: '/home' },
{ path: '/home', component: Home },
{ path: '/member', component: Member },
{ path: '/shopcar', component: Shopcar },
{ path: '/search', component: Search }
],
linkActiveClass: 'mui-active'
});
假数据:
lunbo: [
'http://www.itcast.cn/images/slidead/BEIJING/2017440109442800.jpg',
'http://www.itcast.cn/images/slidead/BEIJING/2017511009514700.jpg',
'http://www.itcast.cn/images/slidead/BEIJING/2017421414422600.jpg'
]
引入轮播图组件:
<!-- Mint-UI 轮播图组件 -->
<div class="home-swipe">
<mt-swipe :auto="4000">
<mt-swipe-item v-for="(item, i) in lunbo" :key="i">
<img :src="item" alt="">
</mt-swipe-item>
</mt-swipe>
</div>
</div>
.vue
组件中使用vue-resource
获取数据运行cnpm i vue-resource -S
安装模块
导入 vue-resource 组件
import VueResource from 'vue-resource'
在vue中使用 vue-resource 组件