首页  >  问答  >  正文

如何在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 天前423

全部回复(1)我来回复

  • P粉762447363

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

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

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

    回复
    0
  • 取消回复