Quasar is a popular Vue UI library for developing good looking Vue apps.
In this article, we’ll take a look at how to create Vue apps with the Quasar UI library.
Popup Proxy
We can use Quasar’s q-popup-proxy
component to add a popup that’s triggered by clicking a button.
For instance, we can write:
<!DOCTYPE html>
<html>
<head>
<link
href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons"
rel="stylesheet"
type="text/css"
/>
<link
href="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.min.css"
rel="stylesheet"
type="text/css"
/>
</head>
<body class="body--dark">
<script src="https://cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.umd.min.js"></script>
<div id="q-app">
<q-layout
view="lHh Lpr lFf"
container
style="height: 100vh;"
class="shadow-2 rounded-borders"
>
<div class="q-pa-md">
<q-btn push color="primary" label="button">
<q-popup-proxy>
<q-banner>
<template v-slot:avatar>
<q-icon name="signal_wifi_off" color="primary" />
</template>
You are offline
</q-banner>
</q-popup-proxy>
</q-btn>
</div>
</q-layout>
</div>
<script>
new Vue({
el: "#q-app",
data: {}
});
</script>
</body>
</html>
We add it inside the button to make the popup display when we click the button.
The popup content is inside the q-popup-proxy
‘s default slot.
We can make the popup display when we right-click with the context-menu
prop:
<!DOCTYPE html>
<html>
<head>
<link
href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons"
rel="stylesheet"
type="text/css"
/>
<link
href="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.min.css"
rel="stylesheet"
type="text/css"
/>
</head>
<body class="body--dark">
<script src="https://cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.umd.min.js"></script>
<div id="q-app">
<q-layout
view="lHh Lpr lFf"
container
style="height: 100vh;"
class="shadow-2 rounded-borders"
>
<div class="q-pa-md">
<q-btn push color="primary" label="button">
<q-popup-proxy context-menu>
<q-banner>
<template v-slot:avatar>
<q-icon name="signal_wifi_off" color="primary" />
</template>
You are offline
</q-banner>
</q-popup-proxy>
</q-btn>
</div>
</q-layout>
</div>
<script>
new Vue({
el: "#q-app",
data: {}
});
</script>
</body>
</html>
We can also make the popup trigger when we click on an icon that we have in the input with:
<!DOCTYPE html>
<html>
<head>
<link
href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons"
rel="stylesheet"
type="text/css"
/>
<link
href="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.min.css"
rel="stylesheet"
type="text/css"
/>
</head>
<body class="body--dark">
<script src="https://cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.umd.min.js"></script>
<div id="q-app">
<q-layout
view="lHh Lpr lFf"
container
style="height: 100vh;"
class="shadow-2 rounded-borders"
>
<div class="q-pa-md">
<q-input filled v-model="input" mask="date" :rules="['date']">
<template v-slot:append>
<q-icon name="event" class="cursor-pointer">
<q-popup-proxy :breakpoint="600">
<q-date v-model="input"></q-date>
</q-popup-proxy>
</q-icon>
</template>
</q-input>
</div>
</q-layout>
</div>
<script>
new Vue({
el: "#q-app",
data: {
input: undefined
}
});
</script>
</body>
</html>
Pull to Refresh
We can add pull to refresh functionality with the q-pull-to-refresh
component.
For instance, we can write:
<!DOCTYPE html>
<html>
<head>
<link
href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons"
rel="stylesheet"
type="text/css"
/>
<link
href="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.min.css"
rel="stylesheet"
type="text/css"
/>
</head>
<body class="body--dark">
<script src="https://cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.umd.min.js"></script>
<div id="q-app">
<q-layout
view="lHh Lpr lFf"
container
style="height: 100vh;"
class="shadow-2 rounded-borders"
>
<div class="q-pa-md">
<div class="q-pa-md scroll" style="height: 300px;">
<q-pull-to-refresh @refresh="refresh">
<div v-for="n in num" :key="n" class="q-mb-sm">
{{num - n}} - Lorem ipsum
</div>
</q-pull-to-refresh>
</div>
</div>
</q-layout>
</div>
<script>
new Vue({
el: "#q-app",
data: {
num: 50
},
methods: {
refresh(done) {
setTimeout(() => {
this.num += 50;
done();
}, 1000);
}
}
});
</script>
</body>
</html>
We have the items that we can pull to refresh inside tyhe q-pull-to-refresh
component.
In the refresh
handler, we call done
when we’re done refreshing the content.
Conclusion
We can add popups and pull to refresh into our Vue app with Quasar.