Heim  >  Fragen und Antworten  >  Hauptteil

Wie verwende ich Konstanten von Vue-Methoden in Vue-Vorlagen, um konstante Ergebnisse anzuzeigen?

Ich habe diese Alarmkomponente und versuche im Textfeld const „item“ zu verwenden. Das const „item“ befindet sich in der Vue-Methode. Ist es möglich, das const „item“-Ergebnis in diesem Alarmtextfeld abzurufen? Ich habe {item} {{item}} ohne Erfolg ausprobiert. Danke

<alert
        v-if="warning"
        :show-alert="showAlert"
        :options="{
          body: "message" {item} {{item}}
        }"
        color="#ffc107"
        style="max-width: 670px; width: 100%;"
        @input="showAlert = false"
      />
...


export default {
  data () {
return {
  warning: '',
  showAlert: true,
  item: null
}


},

...

methods: {
const item = result.hits[0].refs.id[0]

...

P粉946437474P粉946437474211 Tage vor417

Antworte allen(1)Ich werde antworten

  • P粉762447363

    P粉7624473632024-03-22 11:27:45

    我的答案是否定的,为什么要在 HTML 模板中绑定常量?因为您的数据对象中已经有 item 属性。您可以更新该属性中的项目值,而不是在 const 中分配该值。

    例如: this.item = '项目值' 而不是 const item = '项目值'

    Antwort
    0
  • StornierenAntwort