Cách gửi biến từ thành phần cha mẹ sang thành phần con khi tôi sử dụng "nhấp chuột" tại vue.js?

lập trình


Tôi có hai thành phần, TimeLine.vue(Parent) và SuspendsMemo.vue(Child)

TimeLine.vue(Cha mẹ)

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)
    }
  },

Khi tôi nhấp vào ↑, làm cách nào để gửi biến ‘url’ tới thành phần SuspendsMemo.vue(Child)?

Những gì tôi đã thử:

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

Giải pháp 1

Nếu tôi đang muốn làm điều này, tôi sẽ xem xét Slots hoặc Props trong Vue. Đối với trường hợp cụ thể này, khi bạn tỏ ra không lo lắng quá nhiều về khía cạnh thị giác bị ảnh hưởng ở trẻ, tôi sẽ sử dụng Props. Bạn có thể lấy một ví dụ về đạo cụ đây[^].

コメント

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