You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.2 KiB

  1. <app-sidebar-button>
  2. <button class="button m-bottom-0" type="button" onclick={ (event) => { handleClick(event) } }></button>
  3. <script>
  4. export default {
  5. state: {
  6. element: undefined,
  7. data: []
  8. },
  9. /**
  10. *
  11. *
  12. */
  13. onBeforeMount() {
  14. // getting innerHtml before rendering component
  15. this.content = this.root.innerHTML;
  16. this.root.innerHTML = '';
  17. },
  18. /**
  19. *
  20. *
  21. */
  22. onMounted() {
  23. this.state.element = document.querySelector(this.props.selector)
  24. // adding innerHtml to button
  25. this.$('button').innerHTML = this.content;
  26. },
  27. /**
  28. *
  29. * @param {[type]} event
  30. * @return {[type]}
  31. */
  32. handleClick(event) {
  33. event.preventDefault()
  34. const customEvent = new CustomEvent(this.props.event)
  35. this.state.element.dispatchEvent(customEvent, this.state.data)
  36. }
  37. }
  38. </script>
  39. </app-sidebar-button>