Skip to content
Discussion options

You must be logged in to vote

Here's a plugin for the v2 style $refs, where you would use like $v2refs.something.value

Alpine.magic('v2refs', (el, { Alpine: { closestRoot } }) => {
  const root = closestRoot(el)
  return new Proxy({}, {
    get(_, prop) {
      return root.querySelector(`[x-ref=${prop}]`)
    }
  })
})

Demo: https://codepen.io/KevinBatdorf/pen/VwbvZBR?editors=1010

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
2 replies
@AdamSCMM
Comment options

@KevinBatdorf
Comment options

Comment options

You must be logged in to vote
6 replies
@danddanddand
Comment options

@KevinBatdorf
Comment options

@KevinBatdorf
Comment options

@KevinBatdorf
Comment options

@KevinBatdorf
Comment options

Answer selected by AdamSCMM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants