首頁  >  問答  >  主體

如何在Vue模板中使用Vue方法的常數來顯示常數結果?

我有這個警報組件,在正文字段中我嘗試使用 const“item”。 const“item”位於Vue方法中,是否可以在該警報主體欄位中得到const“item”結果?我嘗試了 {item} {{item}} 但沒有成功。謝謝

<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 天前426

全部回覆(1)我來回復

  • P粉762447363

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

    我的答案是否定的,為什麼要在 HTML 模板中綁定常數?因為您的資料物件中已經有 item 屬性。您可以更新該屬性中的項目值,而不是在 const 中指派該值。

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

    #

    回覆
    0
  • 取消回覆