一些提醒
q-dialog 的自定义弹框
备注
弹框组件必须类似如下。
<template>
<q-dialog ref="dialogRef" @hide="onDialogHide">
<q-card class="q-dialog-plugin">
<!--
...content
... use q-card-section for it?
-->
<!-- buttons example -->
<q-card-actions align="right">
<q-btn color="primary" label="OK" @click="onOKClick" />
<q-btn color="primary" label="Cancel" @click="onDialogCancel" />
</q-card-actions>
</q-card>
</q-dialog>
</template>
<script setup>
import { useDialogPluginComponent } from 'quasar';
const props = defineProps({
// ...your custom props
});
defineEmits([
// REQUIRED; need to specify some events that your
// component will emit through useDialogPluginComponent()
...useDialogPluginComponent.emits,
]);
const { dialogRef, onDialogHide, onDialogOK, onDialogCancel } =
useDialogPluginComponent();
// dialogRef - Vue ref to be applied to QDialog
// onDialogHide - Function to be used as handler for @hide on QDialog
// onDialogOK - Function to call to settle dialog with "ok" outcome
// example: onDialogOK() - no payload
// example: onDialogOK({ /*...*/ }) - with payload
// onDialogCancel - Function to call to settle dialog with "cancel" outcome
// this is part of our example (so not required)
function onOKClick() {
// on OK, it is REQUIRED to
// call onDialogOK (with optional payload)
onDialogOK();
// or with payload: onDialogOK({ ... })
// ...and it will also hide the dialog automatically
}
</script>
使用
import { useQuasar } from 'quasar'
import CustomComponent from '..path.to.component..'
setup () {
const $q = useQuasar()
$q.dialog({
component: CustomComponent,
// props forwarded to your custom component
componentProps: {
text: 'something',
// ...more..props...
}
}).onOk(() => {
console.log('OK')
}).onCancel(() => {
console.log('Cancel')
}).onDismiss(() => {
console.log('Called on OK or Cancel')
})
}
q-page 内容区的大小
备注
如果直接写高度为100vh,那么算上顶部的Header,会导致总高度超过屏幕而出现滚动条。
QPage需要QLayout,因为QLayout控制页面的所有偏移量,并根据其“view”属性配置计算页眉/页脚/抽屉使用的空间。 默认情况下,您的QPage组件上将设置一个min-heightCSS属性,以确保内容始终填充屏幕,即使内容只有几行也是如此。
如果您想调整甚至删除此属性,可以使用style-fn属性来实现:
<template>
<q-page :style-fn="myTweak">...</q-page>
</template>
<script>
export default {
// ...
methods: {
myTweak (offset) {
// “offset”是一个数字(像素),
//它表示基于QLayout“view”属性配置的
//屏幕上页眉+页脚的总高度
// 这实际上是Quasar中默认style-fn的功能
return { minHeight: offset ? `calc(100vh - ${offset}px)` : '100vh' }
}
}
}
</script>