可以通过按Enter键而不是点击来打开Quasar PopUpEdit吗?

huangapple go评论65阅读模式
英文:

Is it possible to open Quasar PopUpEdit by pressing Enter key, instead of clicking on it?

问题

尽管 Quasar 文档提到了 show() 事件,以便在程序中打开 QPopUpEdit(而不是通过单击它来实现默认行为),但并没有提供任何示例。在研究后,有人建议使用模板引用,但对我来说,不幸的是它没有起作用。

我已经尝试了使用模板引用,如下所示,但它没有起作用。有人可以帮助我更接近解决方案吗?

<q-popup-edit v-slot="scope" auto-save ref="popUp">
    <q-input v-model="scope.value" autofocus/>
</q-popup-edit>

在脚本中

const popUp = ref()

const enterPressed = () => {
    popUp.show()  
}
英文:

Though Quasar documentation mentions the show() event, in order to programatically open QPopUpEdit (instead of the default behaviour by clicking on it), but there is no any example. After researching it is suggested by others using a template ref, but for me, unfortunately it is not working.

I have tried with template ref, as follows, but it is not working. Can anybody help me to get closer to the solution?

<q-popup-edit v-slot="scope" auto-save ref="popUp">
    <q-input v-model="scope.value" autofocus/>
</q-popup-edit>


In script:

const popUp = ref()

const enterPressed = () => {
    popUp.show()  
}

答案1

得分: 1

只需使用一个按钮。查看示例。

Quasar似乎会自动执行这个操作。但你也可以将按钮的click设置为@click="enterPressed"

示例

const { createApp, ref } = Vue;

const app = createApp({
  setup () {  
    return { label: ref('Click me') }
  }
})

app.use(Quasar)
app.mount('#q-app')
a, label { line-height: 3; }
<!DOCTYPE html>
<html>
  <head>
    <link href="https://cdn.jsdelivr.net/npm/quasar@2.11.5/dist/quasar.prod.css" rel="stylesheet" type="text/css">
  </head>
  <body>
    <div id="q-app">
      <a href="#focus" autofocus>点击这里聚焦。</a> 然后按:<kbd>TAB</kbd>, <kbd>ENTER</kbd>
      <p>
        <button type="button" autofocus>PopUp</button><br/>
        <label>{{label}}</label>
        <q-popup-edit v-model="label" v-slot="scope" auto-save>
          <q-input v-model="scope.value" dense autofocus counter @keyup.enter="scope.set"/>
        </q-popup-edit>
      </p>
    </div>    
    <script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/quasar@2.11.5/dist/quasar.umd.prod.js"></script>
  </body>
</html>
英文:

Just use a button. See the playground.

Quasar seems to do it automatically. But you could also set button's click to @click=&quot;enterPressed&quot;

Playground

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

const { createApp, ref } = Vue;

const app = createApp({
  setup () {  
    return { label: ref(&#39;Click me&#39;) }
  }
})

app.use(Quasar)
app.mount(&#39;#q-app&#39;)

<!-- language: lang-css -->

a, label { line-height: 3; }

<!-- language: lang-html -->

&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;link href=&quot;https://cdn.jsdelivr.net/npm/quasar@2.11.5/dist/quasar.prod.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id=&quot;q-app&quot;&gt;
      &lt;a href=&quot;#focus&quot; autofocus&gt;Click here to focus.&lt;/a&gt; Then press: &lt;kbd&gt;TAB&lt;/kbd&gt;, &lt;kbd&gt;ENTER&lt;/kbd&gt;
      &lt;p&gt;
        &lt;button type=&quot;button&quot; autofocus&gt;PopUp&lt;/button&gt;&lt;br/&gt;
        &lt;label&gt;{{label}}&lt;/label&gt;
        &lt;q-popup-edit v-model=&quot;label&quot; v-slot=&quot;scope&quot; auto-save&gt;
          &lt;q-input v-model=&quot;scope.value&quot; dense autofocus counter @keyup.enter=&quot;scope.set&quot;/&gt;
       &lt;/q-popup-edit&gt;
       &lt;/p&gt;
    &lt;/div&gt;    
    &lt;script src=&quot;https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://cdn.jsdelivr.net/npm/quasar@2.11.5/dist/quasar.umd.prod.js&quot;&gt;&lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年2月8日 23:02:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75387665.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定