search

Home  >  Q&A  >  body text

How to use constants of Vue methods in Vue templates to display constant results?

I have this alert component and in the body field I try to use const "item". The const "item" is in the Vue method, is it possible to get the const "item" result in that alert body field? I tried {item} {{item}} without success. Thanks

<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粉946437474250 days ago448

reply all(1)I'll reply

  • P粉762447363

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

    My answer is no, why should we bind constants in HTML templates? Because you already have item property in your data object. You can update the item value in this property instead of assigning the value in const.

    For example: this.item = 'item value' instead of const item = 'item value'

    reply
    0
  • Cancelreply