官网:nodejs.org/en/css
npm install -g @vue/cli
复制代码
安装成功后查看版本:vue -V(大写的V) vue
到你想建立项目的目录下建立项目(WeChat:项目名称)node
vue create project-name
复制代码
default 是 使用默认配置ios
Manually select features 是 是自定义配置 es6
空格键切换选中状态 vue-cli
TypeScript:微软提供的js超集npm
Progressive Web App (PWA) Support:渐进式的网页应用程序。axios
Router:路由bash
Vuex:Vuex是Vue.js应用程序的状态管理模式+库babel
CSS Pre-processors:Sass/Less预处理器
Linter / Formatter:代码风格检查
Unit Testing:支持单元测试
E2E Testing:支持E2E测试
cd project-name // 进入项目根目录
npm run serve // 运行项目
复制代码
1.删除src/cpomponents项目的文件
2.删除assets下面的图片
3.删除pubilc下面的favicon.icon
src/App.vue:
<template>
<div id="app">
<home></home>
</div>
</template>
<script>
import home from "./views/Home";
export default {
components: {
home
}
};
</script>
<style lang="less">
</style>
复制代码
src/views/Home.vue:
<template>
<div class="home">home</div>
</template>
<script>
export default {
name: "home",
};
</script>
复制代码
在wechat项目中安装 Axios
npm install --save axios
复制代码
1.修改src/main.js
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// 1.引入axios
import axios from 'axios'
Vue.config.productionTip = false
// 2.把axios绑定到vue实例的属性$axios
Vue.prototype.$axios = axios
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
复制代码
src/App.vue
<template>
<div id="app">
<home></home>
</div>
</template>
<script>
import home from "./views/Home";
export default {
components: {
home
}
};
</script>
<style lang="less">
</style>
复制代码
<template>
<div class="home">home</div>
</template>
<script>
export default {
name: "home",
mounted() {
this.$axios
.get("https://www.easy-mock.com/mock/5d395ce7fa347e75e540dbeb/zl/Update")
.then(res => {
console.log(res);
});
}
};
</script>
复制代码
在src/main.js引入
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// 引入iconfont的样式
import './assets/iconfont/iconfont.css'
// 1.引入axios
import axios from 'axios'
Vue.config.productionTip = false
// 2.把axios绑定到vue实例的属性$axios
Vue.prototype.$axios = axios
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
复制代码
在src/views/Home.vue修改
<template>
<div class="home">home
<div class="iconfont icon-iconfonthome0"></div>
</div>
</template>
<script>
export default {
name: "home",
mounted() {
this.$axios
.get("https://www.easy-mock.com/mock/5d395ce7fa347e75e540dbeb/zl/Update")
.then(res => {
console.log(res);
});
}
};
</script>
复制代码
npm i vant -S
复制代码
安装插件
npm i babel-plugin-import -D
复制代码
在babel.config.js配置
module.exports = {
presets: [
'@vue/app'
],
plugins: [
['import', {
libraryName: 'vant',
libraryDirectory: 'es',
style: true
}, 'vant']
]
}
复制代码
在src/main.js配置
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// 引入iconfont的样式
import './assets/iconfont/iconfont.css'
// 引入Vant UI组件的样式
import 'vant/lib/index.css'
// 1.引入axios
import axios from 'axios'
Vue.config.productionTip = false
// 2.把axios绑定到vue实例的属性$axios
Vue.prototype.$axios = axios
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
复制代码
src/views/Home.vue
<template>
<div class="home"> home <div class="iconfont icon-iconfonthome0"></div> <van-button type="primary">主要按钮</van-button> </div> </template>
<script>
import Vue from "vue";
import { Button } from "vant";
Vue.use(Button);
export default {
name: "home",
mounted() {
this.$axios
.get("https://www.easy-mock.com/mock/5d395ce7fa347e75e540dbeb/zl/Update")
.then(res => {
console.log(res);
});
}
};
</script>
<style lang="less" scoped>
</style>
复制代码
px
做为单位,若是须要使用rem
单位,推荐使用如下两个工具:1.postcss-pxtorem是一款postcss插件,能够将单位转换为rem
npm install postcss-pxtorem --save-dev
复制代码
2.lib-flexible用于设置 rem 基准值
npm i lib-flexible --save
复制代码
module.exports = {
plugins: {
'autoprefixer': {
browsers: ['Android >= 4.0', 'iOS >= 7']
},
'postcss-pxtorem': {
rootValue: 37.5,
propList: ['*']
}
}
}
复制代码
// 引入lib-flexible
import 'lib-flexible/flexible'
复制代码