GITHUB: 使用Quasar设计旅游网站
文章连接: 使用Quasar设计Material和IOS风格的响应式网站
Quasar
是一款基于Vue.js
开发的UI
框架,可让你轻松构建网站简洁明快的界面,更重要的是它还能让你轻松作好RWD
(响应式网站设计),除此以外还能帮助你加上PWA
,使你的网页变成手机上的App
。javascript
如下内容来自官网Quasar Framework,归纳了Quasar
的主要特色。css
Quasar
是MIT
许可的开源框架(基于Vue),可帮助Web
开发人员建立:html
PWA
Apache Cordova
构建移动App
Electron
)Material
及IOS
两种主题RWD
快速响应UI
组件库Vuex
、VueRouter
、Vuei18n
(多国语系)首先安装Node.js
和vue-cli
,具体安装方法查看官网资料。vue
而后安装Quasar
,npm install -g quasar-cli
。java
最后搭建项目:quasar init <folder name>
webpack
取代main.js
的quasar.config.js
设置文件:git
import components
i18n
设置多国语系icons
移除注释便可使用开发模式
下的HTTPS以及port
设置CSS
动画设置PWA
、manifest
等设置quasar.config.js
plugins
之前在Vue
安装其余的plugin
会在main.js
里引入,而在Quasar
就会取代main.js
成为所有配置文件。github
css
CSS的引入都会放在这个文件,默认的位置/src/css
,所需的CSS库已经准备好,能够直接使用。web
extra
这里是设置是否引入quasar-extras的内容。ajax
Package | name | 说明 |
---|---|---|
Roboto Font | roboto-font |
Material主题的建议字体 |
Roboto Font Latin Extended | roboto-font-latin-ext |
Material主题的建议字体 |
Material Icons | material-icons |
Material风格的icon |
MDI (Material Design Icons) | mdi |
Material风格的icon 扩展 |
Font Awesome | fontawesome |
自由选择icon |
Ionicons | ionicons |
ionicons 的icon |
Animate.css | animations |
网页组件动画 |
scopeHoiting
默认true
,用来提高webpack
运行时的性能
VueRouterMode
设置Vue Router
的模式,有history
、hash
两种值。
vueCompiler
包含两种Vue的编译模式vue runtime
+compiler
,默认只有runtime-only
运行时编译
gzip
使网站支持gzip
的格式。
analyze
在build
时会运行webpack-bundle-analyzer
工具。
extractCSS
提取CSS到文件中。VueLoader
extendWebpack
在dev
模式中服务器的设置。
https
port
设置成指定的port
,当quasar在运行dev
模式时,遇到相同的port
时会本身再+1
。
open
是否在dev
指令执行完成后,自动开启此网站的分页在浏览器上。
quasar dev
打开初始页面,页面的header
和drawer
都是在layout/MyLayout.vue
里。
一些经常使用的属性:
属性 | 取值 | 说明 |
---|---|---|
side |
String |
有两个值left ,right ,决定要出如今左边仍是右边 |
overlay |
Boolean |
设置侧边栏弹出时是挤压q-page-container 仍是直接盖在上面 |
content-style |
Object |
设置侧边栏的CSS |
content-class |
String/Object/Array |
设置侧边栏的class |
mini |
Boolean |
把侧边栏缩小到只有icon |
这里的CSS要用
Object
的方式传入。
:content-style="{color: 'red'}"
演示项目:
<q-layout-header> <q-toolbar color="primary" text-color="primary" inverted> <q-toolbar-title> 好玩旅游网 <div slot="subtitle">WeFunWeb</div> </q-toolbar-title> <div class="gt-xs"> <q-btn class="q-mr-md" flat>精选景点</q-btn> <q-btn class="q-mr-md" flat>美食地图</q-btn> <q-btn class="q-mr-md" flat>夜宿晓行</q-btn> <q-btn class="q-mr-md" flat>夜宿晓行</q-btn> <q-btn class="q-mr-md" flat>注册</q-btn> <q-btn class="q-mr-md" flat>登陆</q-btn> </div> </q-toolbar> </q-layout-header>
color
Quasar内建色:color-palette
在/src/css/themes/common.variables.styl
里面增长调色板的颜色。
inverted
让背景色变成白色,而后使原来白色的文字变成设置的背景色。
glossy
加上玻璃效果
gt-xs
用来设置显示像素高于576px
的页面样式。
q-mr-md
mr
等于margin-right
sm
就是size
的值为small
其余非外观的功能属性:
disable
,:disable="true"
时按钮禁用label
设置按钮的文字type
能够是button
、submit
、reset
其中一种loading
,值为true
显示读取中percentage
显示读取的圆圈,要跟loading
一块儿使用dark-percentage
用在亮色系的按钮上修改Drawer
v-model="rightDrawerOpen"
控制弹出侧边栏的位置content-class="bg-grey-10"
背景色side="right"
按钮设置在多边设置了rightDrawerOpen
须要加到data
里。
export default { name: 'MyLayout', data () { return { rightDrawerOpen: false } } }
控制显示的class
用lt-sm
只要像素小于sm(768px)
就会显示该区域。
ListItem
使用Dark属性使得组件内容在暗色背景下更好显示
List中可用组件,这些组件须要本身去配置文件中自行引入。
QListHeader
List上的标题QItemSeparator
分割线QItem
QItemSide
可分红左右两侧的区块QItemMain
中间的区块QItemTitle
区块中的标题在src/pages/
下新建Index
文件夹,并在此文件夹下新建Index.vue
做为首页,删除原来的Index.vue
文件。
在src/router/routers.js
修改Index.vue
的路径。
在src/pages/Index
下新建SectionCarousel.vue
,并在Index.vue
中引入。
而后再template
下的q-page
中加入section-carousel
<template> <q-page> <section-carousel></section-carousel> </q-page> </template>
在设置文件quasa.config.js
中引入:
framework: { components: [ 'QCarousel', 'QCarouselSlide', 'QCarouselControl' ... ], }
<template> <q-carousel color="white" infinite arrows autoplay height="400px" > <q-carousel-slide img-src="statics/images/papercut1.jpg"/> <q-carousel-slide img-src="statics/images/papercut2.jpg"/> </q-carousel> </template>
Quasar在carousel
中有个子组件QCarouselControl
用来自定义按钮在页面上。
根据官方文档的范例,QCarouselControl
要放在QCarousel
的最后面,也就是QCarouselSlide
的后面。
<q-carousel-control position="center" slot="control-nav" slot-scope="carousel" class="carouselInput"> </q-carousel-control>
在q-carousel-control
中加入内容:
<div class="main"> <h6 class="title">新锐旅游网站</h6> <p class="subtitle">您身边的好玩专家</p> <p>发现周边好玩的地方,玩得快乐,玩得精彩。</p> </div>
<style lang="stylus" scoped> .carouselInput { width: 90% } .carouselInput .main { text-align center color: #f50057 } .carouselInput .title { font-size 48px } .carouselInput .subtitle { font-size 24px } </style>
@media (min-width: 768px) { .carouselInput .title { font-size 48px } .carouselInput .subtitle { font-size 24px } } @media (max-width: 768px) { .carouselInput .title { font-size 24px } .carouselInput .subtitle { font-size 16px } }
input
首先到quasar.config.js
中引入QInput
framework: { components: ['QInput'] }
在<div class="main">
后面加入q-input
内容:
<q-input inverted-light color="white" placeholder="输入城市/景点 或是想去的地方" :after="[{icon:'fas fa-search-location'}]" v-model="search"> </q-input>
inverted
显示背景 color
主题颜色after
用来显示输入框先后icon
最后绑定v-model="search"
,此时须要在data
中添加value
值,不然会报错。
data() { return { search: '' } }
使用 Flex CSS调整组件长度。
<div class="row"> <div class="col-md-2 col-xs-1"></div> <div class="col-md-8 col-xs-10"> <q-input ...></q-input> </div> <div class="col-md-2 col-xs-1"></div> </div>
autocomplete
引入QAutocomplete
组件:
framework: { components: ['QAutocomplete'] }
加入q-autocomplete
:
<q-input ...> <q-autocomplete :static-data="{field: 'label', list: countries}"/> </q-input>
static-data
field
用于搜索数据的栏位list
搜索的数据来源countries: [ {label: '广州市', icon: 'fas fa-map-marker-alt'}, {label: '深圳市', icon: 'fas fa-map-marker-alt'}, {label: '珠海市', icon: 'fas fa-map-marker-alt'}, {label: '[网美景点]香山公园,秋季赏枫胜地', stamp: '北京市'}, {label: '珠海长隆[海豚剧场]精彩不容错过!精彩变身演出抢先看', stamp: '珠海,长隆', rightTextColor: 'pink-13'} ]
filter
在q-autocomplete
中加入filter
:
<q-autocomplete :static-data="{field: 'label', list: countries}" :filter="advFilter" />
引入lodash
处理filter
。
在quasar.config.js
中引入QPopover
。Popover
no-focus
不设焦点fit
弹出框跟输入框等长v-show="!search"
弹框和候选框不一样时出现使用FlexCSS
来进行排版。
<div class="row viewList"> <div class="col-sm-4 col-xs-12"></div> <div class="col-sm-4 col-xs-12"></div> <div class="col-sm-4 col-xs-12"></div> </div>
设配手机端,在CSS底部加入:
@media (max-width: 576px) { .viewList { width: 280px } }
解决在手机像素下原来Popover
不能自动fix
的问。这里应该是小于Popover的fix
的最小宽度。
列表类直接用list
作最快。
<div class="col-sm-4 col-xs-12"> <q-list> <q-list-header>热门目的地</q-list-header> <q-item> <q-item-main>珠海</q-item-main> </q-item> </q-list> </div>
在src/components
下新建LIcon.vue
,提高组件复用。
主要使用了q-icon
来引入Font Awesome的icon
。
具体代码:
SectionCarousel.vue
src/components/LIcon.vue
在src/pages/Index
下新建SectionCards.vue
组件,用来做为卡片区块。
在Index.vue
中引入SectionCards.vue
。
<div class="row"> <div class="col-12"><b>本月最精选</b></div> <div class="col-lg-3 col-sm-6 col-xs-12">卡片一</div> <div class="col-lg-3 col-sm-6 col-xs-12">卡片二</div> <div class="col-lg-3 col-sm-6 col-xs-12">卡片三</div> <div class="col-lg-3 col-sm-6 col-xs-12">卡片四</div> </div>
卡片内的内容都会大量重复,因此直接把卡片独立成一个组件。
在src/components/
下新建一个LCard.vue
。
在
quasar.config.js
中引入卡片组件
Cards
framework: { components: [ 'QCard', 'QCardTitle', 'QCardMain', 'QCardMedia', 'QCardSeparator', 'QCardActions' ] }
卡片主要分红三个部分:
q-card-media
放照片影片的区块q-card-title
卡片的标题q-card-main
卡片的主内容q-card-actions
用来放按钮等操做的区块q-card-separator
分隔线在SectionCards.vue
中引入LCard.vue
。
<div class="col-lg-3 col-sm-6 col-xs-12"> <l-card/> </div>
import LCard from 'src/components/LCard.vue' export default { components:{ LCard }, }
继续补上评分和地标的Icon
。
让LCard.vue
可以动态获取数据:
<template> <q-card inline> <q-card-media> <img :src="image"/> </q-card-media> <q-card-title> <span>{{title}}</span> <div class="q-mt-sm" slot="subtitle"> <l-icon :icon="'fas fa-star'" :text="rate" :color="'orange'" class="q-mr-md"/> <span class="q-mr-sm">{{comment}}个评价</span> <span>{{view}}人浏览</span> </div> </q-card-title> <q-card-main> <l-icon :icon="'fas fa-map-marker-alt'" :text="locate" :color="'grey'" class="q-mr-md"/> </q-card-main> </q-card> </template> <script> import LIcon from 'src/components/LIcon'; export default { name: "LCard", props: { image: String, title: String, rate: String, comment: String, view: String, locate: String }, components: { LIcon } } </script>
新增一个data
数据monthBestList
,而后在template
模板中使用v-for
获取数据并显示。
<template v-for="(data,index) in monthBestList"> <div class="col-lg-3 col-sm-6 col-xs-12 q-pa-sm" :key="index"> <l-card :title="data.title" :rate="data.rate" :comment="data.comment" :view="data.view" :locate="data.locate" :image="data.image" /> </div> </template>
在src/pages
下新建place
文件夹,并在此文件夹下新建Index.vue
做为文章的主要页面。
要进行页面导航/切换须要用到Vue Router。
在router/routes.js
中加入导航:
const routes = [ { path: '/', component: () => import('layouts/MyLayout.vue'), children: [ {path: '', component: () => import('pages/Index')}, {path: 'Place', component: () => import('pages/Place')} ] } ];
在http://localhost:8080/#/place
中查看效果。
视差(Parallax)
在quasar.config.js
中引入QParallax
组件。
<template> <q-page> <q-parallax :src="localData.image" :height="400"> <p>{{ localData.title }}</p> </q-parallax> </q-page> </template>
按照8格+4格进行排版:
<div class="row place-main"> <div class="col-8"></div> <div class="col-4"></div> </div>
CSS补上左右margin 5%
让页面看起来不会太满。
.place-main { margin-left 5% margin-right 5% }
这里要用Quasar的面包屑BreadCrumbs组件。
在quasar.config.js
中引入:
'QBreadcrumbs', 'QBreadcrumbsEl',
这里按照8格+4格
设定,左侧栏要设为文字靠右对齐。
引入LIcon.vue
图标组件:
<div class="col-8 info-left"> <l-icon class="q-mt-sm" :text="'景点编号:' + localData.id" :icon="'fas fa-tag'" :color="'grey'"/><br> ... </div>
评分组件Rating
表单字段(Field)
Field的组件有QInput
、QSeclet
、QDatetime
、QChipsInput
在quasar.config.js
中引入组件
<q-field label="信箱"> <q-input suffix="@gmail.com" v-model="model"/> </q-field>
label
设置标题文字icon
设置标题的icon
icon-color
设置标题icon
的颜色helper
组件地下的辅助文字error
控制组件在错误时会变成红色警示error-label
错误时会显示的文字warning
控制组件是否为警告状态warning-label
同error-label
count
显示目前输入多少文字inset
用来为没有icon/label
的栏位留空orientation
组件的排列方向(水平horizontal
/垂直vertical
)label-width
文字区块的宽度(以12
格宽度划分)假设文字的宽度要和输入同样长,则设定为6
dark
是文字反白,适用在暗色背景下Chips Input
<q-chips-input float-label="兴趣" v-model="model" />
export default { data() { return { model: [] } } }
chips-color
改变chips
的颜色chips-bg-color
改变chips
的背景颜色add-icon
替换输入时显示在右边的enter
按钮icon
prefix
加入前缀文字(不影响array
内的值)suffix
加入后缀文字,能够跟前缀一块儿用hide-underline
移除本来输入框的底线no-parent-field
若是外面套有QField,能够避免跟QField的效果连结upper-case
自动转大写lower-case
自动转小写大部分组件都会重复的基本属性
float-label
悬浮标题stack-label
固定式标题color
组件颜色inverted
是否有背景色inverted-light
改善亮色背景下组件的显示dark
改善暗色背景下组件的显示error
错误warning
警告disable
跟readonly
相似,可是会有灰键效果@input(newVal)
输入文字的同事就会触发@change(newVal)
数组数值改变触发@clear(clearVal)
数组被清空时触发@duplicate(val)
输入重复的值时触发@add(val)
输入时触发@remove({index, value})
其中一个组件被删除时触发这里的用法一般都是在组件中加入red
属性,而后再其余地方使用this.$refs
来对这些组件进行操做。
add(value)
加入值到组件的数组中remove(index)
删除指定索引的值focus()
聚焦在组件上select()
选择组件clear()
清除组件中数组的值<q-chips-input ref="myChipInput" />
addSomething() { this.$refs.myChipInput.add('Hello Quasar') }
引入组件
QRadio
,
单选框(Radio)
<q-field label="黄金周去哪玩?" orientation="vertical"> <q-radio v-model="model" label="去杭州" val="hangzhou"/> <q-radio v-model="model" label="去北京" val="beijing"/> <q-radio v-model="model" label="去成都" val="chengdu"/> </q-field>
val
存储绑定变量的值label
组件上的文字left-label
设定为true
时,文字会改变显示在选项的左边checked-icon
改变选取时的iconunchecked-icon
改变未选取时的iconcolor
改变组件的颜色keep-color
没选取时也会有颜色(默认是灰色)readonly
只读属性disable
禁用dark
在暗色背景时,凸显组件文字no-focus
不会触发聚焦事件@input
选取时触发@blur
失去焦点(点到其余地方)时触发@focus
聚焦(点选该组件)时触发复选框(Checkbox)
在quasai.config.js
中引入QCheckbox
。
复选框须要绑定数据类型为Array
,也须要和QField
一块儿使用。
val
数值,加入到v-model
绑定的变量中true-value
若是model
不是数组,在选取时会给model
值true
,用来取代true
false-value
同上解析indeterminate-value
用来替换null
toggle-indeterminate
使点击可让状态在以上三个中转换切换键Toggle
在quasar.config.js
中引入QToggle
val
,v-model
是Array
,会加在Array
内icon
若是底下两个(checke-icon
、unchecked-icon
)icon 会被覆盖掉选项组option-group
把选项写进一个Array
中,而后直接用v-for
所有渲染出来。
每一步都是同样的,在quasar.config.js
中引入QOptionGroup
。
CheckBox
<template> <q-field orientation="vertical" label="要选购的商品"> <q-option-group type="checkbox" v-model="model" :options="optionList" /> </q-field > </template> <script> export default { name: "index", data() { return { model: [], optionList: [ {label: '鸡蛋', value: 'egg'}, {label: '海带', value: 'seaweed'}, {label: '鸡腿', value: 'lag'}, {label: '牛肉', value: 'beef'} ] } } } </script>
toggle
、radio
和checkbox
相似,只须要修改type
属性值便可
时间日期输入框Datetime,有Material和IOS两种风格。
有两个组件须要引入,一个是输入时显示,一个是默认就是显示的。分别为:
日期时间输入Datetime Input
framework: { components: ['QDatetime'] }
日期时间选择器Datetime Picker
framework: { components: ['QDatetimePicker'] }
// Datetime Input <q-datetime v-model="model" type="date"/> // Datetime Picker <q-datetime-picker v-model="model" type="date"/>
type
,一共有三个值,默认是date
date
单纯日期time
单纯时间datetime
时间+日期minimal
,不显示标题min max
,设置可以选择的日期时间范围<q-datetime v-model="model" type="datetime" max="2019/02/27 2:30"/>
format-model
存储的时间格式,有四种选择:
auto
2019-02-27T12:01:00.000+08:00date
"2019-02-27T04:00:00.000Z"number
1541044860000string
2019-02-27T12:01:00.000+08:00format24h
设为24时制的时钟Input
show()
显示输入hide()
隐藏输入toggle()
切换输入clear()
清空modelPicker
setYear(val)
设置年setMonth(val)
设置月setDay(val)
设置日setHour(val)
设置时setMinute(val)
设置分setView(val)
设置要显示的模式clear()
清空model编辑器(WYSIWYG)
在quasar.config.js
中引入QEditor
组件。
<q-editor v-model="model"/>
主要设置页面的属性有三个:
Toolbar
<q-editor v-model="model" :toolbar="[ ['bold','italic','strike','underline'], ['hr','link'], ['fullscreen'], ['print'] ]" />
Definitions
label
要显示的文字icon
要显示的icontip
小提示cmd
若是不想用默认的功能名称,能够用这个绑回你要的功能handler
自定义methods
的function
名称save: { label:'保存', handler: functionName }
disable
禁用<q-editor v-model="model" :toolbar="[ ['bold','italic','strike','underline'], ['hr','link'], ['fullscreen'], ['print'] ]" :definitions="{ bold:{label:'粗体',icon:null,tip:'这是粗体'} }" />
Font
<q-editor v-model="model" :toolbar="[ ['arial','arial_black','comic_sans'], ]" :fonts="{ arial:'Arial', arial_black:'Arial Black', comic_sans:'Comic Sans MS' }" />
@input
输入时触发@fullscreen(true/false)
切换全屏时触发旋转按钮(Knob)
在quasar.config.js
中引入QKnob
组件。
<q-knob v-model="model" :min="0" :max="25" > <q-icon class="q-mr-xs" name="volume_up"/> {{model}} </q-knob>
属性
size
调整组件的大小,默认120px
step
数值的间距decimals
小数点显示的位数min max
最小值和最大值color
、track-color
颜色、未到达的旋转轴颜色line-width
线条的宽度,默认6px
事件
@input(val)
改变时当即触发@change(val)
改变时触发@drag-value(val)
拖动时就会触发操做表(ActionSheet)
在quasar.config.js
中引入ActionSheet
组件,有Material和IOS两种风格。
pluginS
形式
framework: { plugins: ['ActionSheet'] }
components
形式
framework: { components: ['QActionSheet'] }
Vue内
this.$q.actionSheet(configObj)
Vue外
import { ActionSheet } from 'quasar'; ActionSheet.create(configObj)
this.$q.actionSheet({ title: '操做选择', grid: true, //使用格状排版(一排三个) dismissLabel: '取消', //取消按钮的文字 只有IOS主题下可用 默认是cancel actions: [ { label: '抓虫', color: 'green', icon: 'fas fa-bug', handler() { console.log('抓虫大师') } }, { label: '分享到微博', color: 'blue', icon: 'fas fa-weibo' }, { label: '请人帮忙', color: 'black', icon: 'fas fa-alipay' } ] }).then(action => {}).watch(() => {});
跟上面的操做基本上同样,只是可以多监听@show
和@hide
时间。
事件
@ok
点选选项时触发@cancel
取消时触发@show
显示时触发@hide
隐藏时触发@escape-key
按Esc时触发基本跟上面的Action Sheet同样的操做方法。
this.$q.dialog({ title: '选择主菜', message: '主厨精心特制主餐请选择', color: 'red-13', ok: true, cancel: true, preventClose: true, //设置为true,除非按cancel或是ok,否则不会关闭窗口 noBackdropDismiss: false, //按空白的地方不会关闭窗口 noEscDismiss: false, //按Esc不会关闭窗口 stackButtons: false, //为true时会将ok/cancel按钮垂直排列 position: 'top', //设置窗口显示的位置 //使用input prompt: { mode: '顶级和牛帝王蟹', type: 'text' }, //使用option options:{ type:'radio', model:'beef', //默认的选项 items:[ {label:'绝对不加热生牛排',value:'beef'}, {label:'极地冰山沙漠鲔鱼',value:'tuna'}, {label:'超级漆黑山洞野猪肉',value:'pork'} ] } }).then(action => {}).watch(() => {});
在配置文件中引入QDialog
组件。
<q-dialog> <span slot="title">标题</span> <span slot="message">正文</span> <span slot="body">主体</span> <span slot="buttons">按钮</span> </q-dialog>
模态框(Modal)
引入QModal
组件,另外加入directives
的CloseOverlay
。
使用按钮或是method
将modal
设为true
才能打开modal
。
全页显示
<q-btn @click="model=true">Open</q-btn> <q-modal v-model="model" content-css="padding: 50px" maximized> <h4>想去哪里玩?</h4> <p>自由行·出国度假</p> <p>泰国、首尔、珠海、九寨沟</p> <q-btn class="q-mt-lg" color="primary" @click="model=false" label="订购行程" /> </q-modal>
最小窗口minimized
设置position
后会自动清除content-css
定义的css
,因此要在里面多一个div
来作padding
。
<q-modal v-model="model" minimized> <div style="padding: 20px"> ... </div> </q-modal>
minimized
,maximized
设置窗口最小化或是最大化no-route-dismiss
、no-esc-dismiss
、no-backdrop-dismiss
分别为控制换页、按下Esc、按黑色背景是否会触发开闭事件content-css
,content-classes
,Modal内的CSS及class,在设置了position
后会无效position
设置弹窗出来的位置position-classes
设置position
后就要用这个来设class
,默认是items-center
,justify-center
transition
,enter-class
,leave-class
能够用自定义的CSS来作出场的动画no-refocus
是否让关闭窗口时聚焦回到打开窗口前的最后一个组件控制打开关闭窗口的一些方法,要搭配this.$refs.窗口名称
来使用。
show
hide
toggle
通知框(Notify)
this.$q.notify({ message: '已保存', timeout: 5000, // type:'positive', //自带选项 color: 'grey', textColor: 'blue', icon: 'fas fa-warning', avatar: 'statics/images', //这个跟icon二选一 detail: '', position: 'top', actions: [ { label: '', icon: '', noDismiss: true, handler() { console.log('hello world'); } } ], onDismiss() { console.log('warning'); } });
import {Notify} from 'quasar'; Notify.create('已保存'); //方式二 Notify.create({ message: '已保存' });
Ajax栏(Ajax Bar)
在quasar.config.js
中引入QAjaxBar
组件。
由于在每一个页面都会用到,因此放在最上层App.vue
。
<div id="q-app"> <router-view></router-view> <a-ajax-bar/> </div>
position
设置组件位置size
载入条的宽度,默认4px
color
默认red
reverse
使进度方向相反@start
开始动做时触发@stop
结束动做时触发start()
stop()
内部加载(Inner Loading)
使用InnerLoading时会做用在relative-position
这个class
下,若是没有添加这个会变成整页。
index.vue
<template> <q-page class="q-ma-lg"> <q-btn @click="$refs.myField.show()">Open</q-btn> <my-field class="relative-position" ref="myField"/> </q-page> </template> <script> import MyField from './MyField'; export default { name: 'PageIndex', components: { MyField } } </script>
MyField.vue
<template> <q-field label="跨年去哪玩?" orientation="vertical" > <q-radio v-model="model" label="去日本" val="japan" checked-icon="far fa-check-circle" keep-color/> <q-radio v-model="model" label="去韩国" val="korea" color="green" keep-color/> <q-radio v-model="model" label="在家待着" val="home" color="red" keep-color/> <q-inner-loading :visible="visible"> <q-spinner-gears size="50px" color="primary"></q-spinner-gears> </q-inner-loading> </q-field> </template> <script> export default { name: "MyField", data() { return { model: false, visible: false } }, methods: { show() { this.visible = true; setTimeout(() => { this.visible = false }, 5000) } } } </script>
效果
CSS间距类CSS Spacing Classes
q-ma-xs
q
做为前缀ma
:
m
类型,margin
a
方向,all
xs
范围的大小跟flex css
一致q-[类型][方向]-[大小]
类型
m
(margin
向外扩)p
(padding
向内扩)总共有7种选择,除了基本的t(top)
,r(right)
,l(left)
、b(bottom)
,a(all)
以外,还有两种x(left+right)
,y(top+bottom)
。
有none
,auto
(只能用在margin
),xs
,sm
,md
,lg
,xl
。
CSS阴影(立面图)CSS Shadows
可视范围CSS Visibility
CSS定位类CSS Positioning Classes
调色板(Color Palette)
在src/css/app.styl
文件中自定义全局CSS
.text-redsp color: #D03F38 .bg-redsp background: #D03F38
这里text
和bg
须要同时设定。
<q-btn color="redsp">Open</q-btn>
多国语系(I18n)
在quasar.config.js
中设置:
framework: { i18n: 'zh-hans' }
let lang = this.#q.i18n.getLocal()
Quasar的切换语系不像是传统的vue-i18n
直接换就能用,必须从新载入新语系的语系档。
<template> <q-btn @click="setLang('zh-hans')">简体中文</q-btn> </template> <script> export default { name: "I18n", methods: { setLang(lang) { import('quasar-framework/i18n/${lang}').then(lang => { this.$q.i18n.set(lang.default) }) } } } </script>
Vue-I18n在src/i18n
里面,参照已经设定的内容添加本身想要的语系。
<p>{{$t('apple')}}</p>
<q-btn @click="setLang()" :label="$t('setting')"></q-btn>
methods: { setLang() { this.$i18m.local = 'zh-CN' } }