简体   繁体   English

如何从外部组件调用 Quasar 对话框?

[英]How to invoke Quasar dialog from external component?

I'm using Vue.js 2.x + Quasar 1.x with http-vue-loader (so no build tools) at the moment.我目前正在使用 Vue.js 2.x + Quasar 1.x 和 http-vue-loader(所以没有构建工具)。

I put a q-dialog in a separate component - let's call it MyComponent, and when I just hook it up in a parent component like so:我将一个 q-dialog 放在一个单独的组件中——我们称之为 MyComponent,当我像这样将它连接到一个父组件中时:

<my-component></my-component>

then nothing happens, it's not even in the DOM... When I just insert the whole q-dialog template into the parent component, without having its separate external component, everything works just fine with a simple v-model.然后什么也没有发生,它甚至不在 DOM 中......当我只是将整个 q-dialog 模板插入到父组件中,而没有单独的外部组件时,使用简单的 v-model 一切正常。

So I imported the component successfully, that part is fine.所以我成功导入了组件,那部分很好。 I was trying to invoke it when I click on a button, but I can't really communicate with the component this way.我试图在单击按钮时调用它,但我无法真正以这种方式与组件进行通信。

Now I've come across two separate ways of creating dialogs in Quasar, the first one is using the component when it's not in its separate component.现在我遇到了在 Quasar 中创建对话框的两种不同方式,第一种是在组件不在其单独组件中时使用该组件。 The second one seems to be the one I might need for a separate dialog component. 第二个似乎是我可能需要的一个单独的对话框组件。 The problem is that importing an external component with vue-http-loader looks like this:问题是使用 vue-http-loader 导入外部组件看起来像这样:

components: {
  'my-component': httpVueLoader('/components/MyComponent.vue'),
},

while according to the Quasar docs, it should look like this:而根据 Quasar 文档,它应该是这样的:

import CustomComponent from '..path.to.component..'

...

this.$q.dialog({
  component: CustomComponent,

...

The docs are a bit confusing to me as well.文档也让我有点困惑。 :/ :/

Unfortunately, I can't see the CustomComponent code, which is required to be created following an interface, which is described in this docpage under the warning.不幸的是,我看不到 CustomComponent 代码,它需要在一个接口之后创建,这在本文档页面的警告下进行了描述。 Make sure that CustomComponent is valid.确保 CustomComponent 有效。

PS - Both of those ways do the same thing but in different ways. PS - 这两种方式都做同样的事情,但方式不同。 With the first one, you'll import that component to another and set him in the template, but with the second one, you'll call a tool, that creates a new modal with passed parameters.对于第一个,您将该组件导入到另一个组件并将其设置在模板中,但是对于第二个,您将调用一个工具,该工具创建一个带有传递参数的新模式。 But the second one doesn't have all functionality compared to the first one.但是与第一个相比,第二个没有所有功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM