类星体中调用对话框的正确方法
<template>
<q-dialog v-model="confirm" ref="dialog" persistent>
<q-card>
<q-card-section class="row items-center">
<span class="q-ml-sm">You must register</span>
</q-card-section>
<q-card-actions align="right">
<q-btn flat label="Save" color="primary" @click="onOKClick"/>
<q-btn flat label="Cancel" color="primary" @click="onCancelClick"/>
</q-card-actions>
</q-card>
</q-dialog>
</template>
<script>
export default {
name: 'UserInfo',
data() {
return {
confirm: false,
}
},
created: function () {
},
methods: {
show() {
this.$refs.dialog.show();
},
hide() {
this.$refs.dialog.hide();
},
onDialogHide() {
this.$emit("hide");
},
onOKClick() {
//code that you want to emit or functionality you want
},
onCancelClick() {
this.hide();
}
}
}
</script>
从您要调用的组件
<template>
<div class='q-pa-md' style='max-width: 300px'>
</div>
</template>
<script>
import UserInfo from "pages/UserInfo";
export default {
name: 'PageIndex',
components: {UserInfo},
data() {
return {
}
},
mounted() {
},
created: function () {
const config = {
headers: {
'Authorization': `Bearer ${this.$kc.token}`,
'Content-Type': 'application/json',
}
};
console.log(this.$kc);
this.$axios.get(`http://localhost:9090/user/${this.$kc.subject}`)
.then((res) => {
console.log(res)
})
.catch(_ => {
//Here the dialog should open
this.$q
.dialog({
component: UserInfo,
parent: this,
})
.onOk(value => {
//Functionality you want on OK click of dialog
})
.onCancel(() => {})
.onDismiss(() => {});
})
},
methods: {
}
}
</script>
之后,您可能会遇到$q.dialog未知的错误,因此请在quaster.js的插件中添加dialog
这样地
import { Quasar, Dialog } from 'quasar'
plugins: [
Dialog
],