Currently, I am developing a Progressive Web App using Vue 2.0 with the Quasar Framework, and one of the challenges I'm facing is how to close the drawer in the left slot of the layout when a menu item is clicked.
Below is the script for the component named Home.ts
:
import Vue from 'vue';
import Component from 'vue-class-component';
import {
QIcon,
QLayout,
QList,
QListHeader,
QItem,
QItemMain,
QItemSide,
QToolbar,
QToolbarTitle,
} from 'quasar';
@Component({
name: 'Home',
components: {
QIcon,
QLayout,
QList,
QListHeader,
QItem,
QItemMain,
QItemSide,
QToolbar,
QToolbarTitle,
}
})
export default class Home extends Vue {
$refs: {
layout: QLayout // Cannot find name 'QLayout'
};
public newPainting() {
this.$refs.layout.toggleLeft();
this.$router.push(`painting/new`);
}
}
The issue arises due to the error message Cannot find name 'QLayout'
, which can be resolved by changing the type of $refs.layout
to any
, as demonstrated below:
$refs: {
layout: any
};
It's puzzling why QLayout
cannot be found, considering it is utilized in the @Component()
decorator.
Here is the content of the Home.vue
file associated with the component (largely borrowed from the default template provided by quasar-cli):
<template>
<q-layout ref="layout">
<q-toolbar slot="header">
<!-- opens drawer below-->
<button class="hide-on-drawer-visible" @click="$refs.layout.toggleLeft()">
<q-icon name="menu"></q-icon>
</button>
<q-toolbar-title>
echroma
</q-toolbar-title>
</q-toolbar>
<!-- Left Side Panel -->
<div slot="left">
<q-list no-border link inset-delimiter>
<q-list-header>Menu</q-list-header>
<q-item @click="newPainting()">
<q-item-side icon="add_to_photos" />
<q-item-main label="New Painting" sublabel="Start evolving a new painting!" />
</q-item>
</q-list>
</div>
<router-view />
</q-layout>
</template>
<script>
import Home from './Home'
export default Home
</script>
<style>
</style>
Would there be a specific reason why QLayout
might not be accessible within the class declaration?