app.js 514 B

12345678910111213141516171819202122232425
  1. document.addEventListener('alpine:init', () => {
  2. Alpine.data('demo', () => ({
  3. goto (path) {
  4. this.$router.push(path)
  5. },
  6. replaceTo (path) {
  7. this.$router.replace(path)
  8. }
  9. }))
  10. Alpine.directive('hello', (el, { expression }, { evaluate, cleanup }) => {
  11. const $router = evaluate(expression)
  12. const onclick = () => {
  13. $router.push('/')
  14. }
  15. el.addEventListener('click', onclick, true)
  16. cleanup(() => {
  17. el.removeEventListener('click', onclick)
  18. })
  19. })
  20. })