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.
v-close-popup
The v-close-popup
directive that comes with Quasar lets us close a popup when we click on an item that has the directive applied.
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-btn label="Menu" color="primary">
<q-menu>
<q-list dense style="min-width: 100px;">
<q-item clickable v-close-popup>
<q-item-section>Open...</q-item-section>
</q-item>
<q-item clickable v-close-popup>
<q-item-section>New</q-item-section>
</q-item>
<q-separator></q-separator>
<q-item clickable v-close-popup>
<q-item-section>Quit</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
</div>
<script>
new Vue({
el: "#q-app",
data: {}
});
</script>
</body>
</html>
We just add it to the item that we want to have applied to make them close the popup when we click on them.
The directive can also be applied to a dialog box.
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-btn label="Open Dialog" color="primary" @click="dialog = true"></q-btn>
<q-dialog v-model="dialog">
<q-card>
<q-card-section>
<div class="text-h6">Dialog</div>
</q-card-section>
<q-card-section class="row items-center q-gutter-sm">
<q-btn label="Open dialog" color="primary" @click="dialog2 = true">
</q-btn>
<q-btn v-close-popup label="Close" color="primary"></q-btn>
<q-dialog v-model="dialog2">
<q-card>
<q-card-section>
<div class="text-h6">Second dialog</div>
</q-card-section>
<q-card-section class="row items-center q-gutter-sm">
<q-btn
v-close-popup="2"
label="Close both dialogs"
color="accent"
>
</q-btn>
<q-btn v-close-popup label="Close this dialog" color="accent">
</q-btn>
</q-card-section>
</q-card>
</q-dialog>
</q-card-section>
</q-card>
</q-dialog>
</div>
<script>
new Vue({
el: "#q-app",
data: {
dialog: false,
dialog2: false
}
});
</script>
</body>
</html>
We add the v-close-popup
directive to the Close both dialogs button to make it close all popups.
Go Back
We can add the v-go-back
directive to handle back button actions.
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-btn v-go-back=" '/' " color="primary" label="Logout"> </q-btn>
</div>
<script>
new Vue({
el: "#q-app",
data: {}
});
</script>
</body>
</html>
to add the v-go-back
directive to go to the /
path when we click it.
Conclusion
Quasar comes with directives to let us close popups when we click on something.
It also has the v-go-back
directive to let us navigate when clicking an element.