1. 首先去官网找到底部的样式
-
找到你底部样式以后,进去查看效果
-
检查元素,直接将整块代码复制下来
-
对着对应的代码右键
-
然后整块copy下来
2. 下载相应的模块(其他基本的依赖以及安装参考06_02.安装列表,建议先将所有的安装好)
npm i https://github.com/dcloudio/mui.git -S
3. 要操作的文件:
4. 代码:
- src/component/common/footer.vue
<template>
<nav class="mui-bar mui-bar-tab">
<router-link class="mui-tab-item mui-active" to="/">
<span class="mui-icon mui-icon-home"></span>
<span class="mui-tab-label">首页</span>
</router-link>
<router-link class="mui-tab-item" to="/">
<span class="mui-icon mui-icon-extra mui-icon-extra-gift"></span>
<span class="mui-tab-label">商品购买</span>
</router-link>
<router-link class="mui-tab-item" to="/">
<span class="mui-icon mui-icon-extra mui-icon-extra-cart"><span class="mui-badge">0</span></span>
<span class="mui-tab-label">购物车</span>
</router-link>
<router-link class="mui-tab-item" to="/">
<span class="mui-icon mui-icon-gear"></span>
<span class="mui-tab-label">设置</span>
</router-link>
</nav>
</template>
<script>
export default {
}
</script>
<style scoped>
</style>
- src/component/common/header.vue
<template>
<header>
<mt-header fixed title="小买卖"></mt-header>
</header>
</template>
<script>
export default {
}
</script>
<style scoped>
</style>
- src/component/common/index.js
// 编写属于自己的公共Vue组件库
import HeaderComponent from './header.vue';
import FooterComponent from './footer.vue';
// Vue插件要求提供一个install方法, 这个方法会被注入Vue
// 需要我们调用Vue的filter component directive去扩展功能
export default {
install(Vue) {
Vue.component('app-header', HeaderComponent);
Vue.component('app-footer', FooterComponent);
}
};
- src/component/App.vue
<template>
<main>
<app-header></app-header>
<app-footer></app-footer>
</main>
</template>
<script>
export default {
}
</script>
<style scoped>
</style>
- src/js/main.js
// from后面的路径, 如果含有./ ../那么就相对于当前文件找文件
// 如果没有, 那么就会去node_modules里面找对应的包
// 1.1 导入第三方包
import Vue from 'vue';
import MintUi from 'mint-ui';
import 'mint-ui/lib/style.css';
import Common from '../component/common'; // 自动找到index.js引入
import 'mui/dist/css/mui.css';
import 'mui/examples/hello-mui/css/icons-extra.css';
// 1.2 启用vue插件
Vue.use(MintUi);
Vue.use(Common);
// 2.1 导入根组件
import AppComponent from '../component/App.vue';
// 2.2 渲染根组件, 启动项目
new Vue({
el: '#app',
render(createNode) {
return createNode(AppComponent);
}
});
- src/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app"></div>
</body>
</html>
- .babelrc
{
"presets": [ "env" ],
"plugins":["transform-runtime"]
}
- .gitignore
# 忽略第三方包, 他们已经记录在package.json文件中了
/node_modules
# 忽略打包后的文件, 因为我们的项目核心是源代码
/dist
# 忽略隐藏文件
.*
# 不忽略git配置文件和babel配置文件
!.gitignore
!.babelrc
- webpack.config.js
const path = require('path');
const HtmlWP = require('html-webpack-plugin');
const CleanWP = require('clean-webpack-plugin');
module.exports = {
// 打包的入口文件
entry: path.resolve(__dirname, './src/js/main.js'),
// 输出
output: {
path: path.resolve(__dirname, './dist'),
filename: 'bundle.js'
},
// 插件配置
plugins: [
new HtmlWP({
template: './src/index.html',
filename: 'index.html',
inject: 'body'
}),
new CleanWP(['dist'])
],
// 模块配置
module: {
// 配置loader规则
rules: [
// css
{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ]
},
// less
{
test: /\.less$/,
use: [ 'style-loader', 'css-loader', 'less-loader' ]
},
// html
{
test: /\.(html|tpl)$/,
use: [ 'html-loader' ]
},
// 静态资源引用
{
test: /\.(png|jpeg|gif|jpg|svg|mp3|ttf)$/,
use: [
{ loader: 'url-loader', options: { limit: 10240 } } // 小于10KB的打包
]
},
// js
{
test: /\.js$/,
use: [ 'babel-loader' ],
exclude: path.resolve(__dirname, '../node_modules')
},
// vue
{
test: /\.vue$/,
use: [ 'vue-loader' ]
}
]
}
};
5. 执行webpack-dev-server
webpack-dev-server
网友评论