当我使用时如何将变量从父组件发送到子组件 "点击" 在 vue.js?

编程


我有两个组件,TimeLine.vue(Parent) 和 SuspishedMemo.vue(Child)

TimeLine.vue(父级)

computed: {
    optionsData () {
        groupTemplate: (item, element, data) => {
          if (!item) return
          var container = document.createElement('div')
          if (item.isDisable !== true) container.setAttribute('class', 'enable')
          var i = document.createElement('i')
          // click
          i.addEventListener('click', () => {
            // itemのidを取得してSuspendedMemoに渡す
            var itemId = item.id
            const url = `/shop/${this.selectedShopId}/room/${itemId}/suspend_memo`
            console.log('Timeline of URL’, url)
            this.data = item.suspendedReserveMemo
            this.openMemo()
          })
          i.setAttribute('class', 'v-icon notranslate mr-2 mdi mdi-close-circle theme--light pink--text')
          container.appendChild(i)
          var span = document.createElement('span')
          span.innerHTML = item.content
          container.appendChild(span)
          return container
        }
      }
      return _.merge({}, base, this.options)
    }
  },

当我点击 ↑ 时,如何将变量 ‘url’ 发送到 SuspishedMemo.vue(Child) 组件?

我尝试过的:

How to send variable from Parent to Child component when I use "click" at Vue.js?

解决方案1

如果我想这样做,我会考虑 Vue 中的插槽或道具。 对于这种特殊情况,您似乎不太担心孩子的视觉方面受到影响,我会坚持使用道具。 您可以获得道具示例 这里[^]。

コメント

タイトルとURLをコピーしました