vue-cli是Vue的脚手架工具,通过vue-cli,可以快速构建一个vue项目,并且vue-cli自带webpack的各种配置。
//3.0 4.0版本
npm install -g vue/cli
vue create project-name
......//2.0版本在4.0版本下运行
npm install -g @vue/cli-init
vue init webpack project-name
......
build:项目的webpack配置文件
config:针对于开发环境和线上环境的配置文件
node_modules:项目的依赖
static:静态资源(本地数据),只有放在static文件下的数据才能被访问到index.html是整个项目最外层的html文件
src:源代码,是主要编写代码的地方: main.js:整个项目的入口文件。App.vue:是总的根组件。APP组件显示当前路由对应的内容。router:index.js:路由assets:项目中的资源,如:iconfontcomponents:项目中的小组件,以.vue结尾的文件都是单文件组件。<tempalate></tempalte>中是组件的模板,<script></script>中是组件的逻辑,<style></style>中是组件的样式。
import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/pages/home/Home'
Vue.use(Router)
export default new Router({
routes: [{path: '/',name: 'Home',component: Home}
]
})
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
(2)因为有些元素的样式在不同浏览器上表现不同,所以引入reset.css文件,重置元素样式,来保障所有浏览器上的样式是一样的。 npm install fastclick --saveimport fastClick from 'fastclick'fastClick.attach(document.body)
组件结构
Home.vue是home页面的根组件,下面有很多子组件。
iconfont的使用
<span class="iconfont"></span>
移动端rem的使用
UI图中:height: 86px(UI图是iphone6的二倍图,所以css中height应为43px)
html中的font-size = 50px,1rem = 50px, 所以43px = 0.86rem
布局:(flexbox布局)
.headerheight: .86remdisplay: flexflex-direction: rowalign-items: center.header_inputflex: 1
用stylus在css中定义变量
//安装
npm install stylus --save
npm install stylus-loader --save
//定义
$bgColor = #00bcd4
//css中引入
@import '~@/assets/styles/varibles.styl'
<style lang="stylus" scoped>
.wrapper >>> .swiper-pagination-bullet-activebackground-color: white !important
.wrapperoverflow: hiddenwidth: 100%height: 0padding-bottom: 31.25% (117/375=31.25%) /*这里的百分比是图片高度相对宽度的百分比,其比值为图片的高宽比。这样设置能实现图片宽高自适应比例。*/
.slide_imgwidth: 100%
页面布局
<template>
<div class="icons"> <!--占位--><div class="icon"> <!--小图标布局--><div class="icon-img"> <!--图片外部包裹一个div--><img class="icon-img-content" src=".png"></div><p class="icon-desc">景点门票</p></div>
</div>
</template><style lang="stylus" scoped>@import '~styles/varibles.styl'.iconsoverflow: hiddenheight: 0padding-bottom: 50%background-color: green.iconposition: relativeoverflow: hiddenfloat: leftwidth: 25%height: 0padding-bottom: 25% //padding-bottom的高宽比的宽度相对的是父元素的宽度background-color: red.icon-imgposition: absolutetop: 0left: 0right: 0bottom: .44rembackground-color: bluebox-sizing: border-boxpadding: .1rem.icon-img-contentheight: 100%display: blockmargin: 0 auto.icon-descposition: absoluteleft: 0right: 0bottom: 0text-align: centerheight: .44remline-height: .44remcolor: $darkTextColor
</style>
图标分页算法
将pages变成二维数组,
pages[0]: array[8],
pages[1]:array[1]。
computed: {pages () {const pages = []this.iconList.forEach((item, index) => {const page = Math.floor(index/8)if(!pages[page]) {pages[page] = []}pages[page].push(item)})return pages}
}
如果文字内容很多,想做成用三个点提示的样式:
overflow: hidden
white-space: nowrap
text-overflow:ellipsis
在vue中发送ajax的工具有fetch函数,vue-resource,axios(第三方模块)。我们使用axios,因为它可以实现跨平台数据请求。
整个首页(Home.vue)发一个ajax请求,获取到数据后传给每一个组件。
methods: { getHomeInfo () {//axios返回的结果是一个promise对象,所以使用then('/api/index.json').HomeInfoSucc)},//数据获取成功后,将数据赋值给当前组件的属性。getHomeInfoSucc (res) {// console.log(res)res = res.dataif ( &&console.log(res) res.data) {this.city = res.data.citythis.swiperList = res.data.swiperList}}},//页面挂载完成后,执行getHomeInfo(),请求ajax数据,mounted () {HomeInfo()}
本来axios获取静态数据,应该是: (’/static/mock/index.json’).HomeInfoSucc)
但是为了上线,应该将静态地址托管为:
(’/api/index.json’).HomeInfoSucc)
使用webpack-dev-server工具
在webpack/index.js中设置
proxyTable: {'/api': {target: 'localhost:8080',pathRewrite: {'^/api': '/static/mock'}}
}
.wrapper >>> .swiper-pagination-bullet-active
background-color: #ffffff !important
本文发布于:2024-01-29 07:22:38,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170648416213647.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |