HeaderMenu.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <script>
  2. import Vue from 'vue'
  3. import { mapState, mapActions } from 'vuex'
  4. import { MA } from 'vuejs/api/ma-axios'
  5. import router from 'vuejs/route'
  6. export default {
  7. router,
  8. props:['id','dom_html'],
  9. data() {
  10. return {
  11. html: null,
  12. template: null
  13. }
  14. },
  15. computed: {
  16. ...mapState({
  17. isloggedin: state => state.User.isloggedin
  18. })
  19. },
  20. beforeMount() {
  21. // console.log("beforeMount header_menu", this.html);
  22. if(!this.template){
  23. // console.log('no home_template');
  24. if(this.dom_html){ // if html prop is available
  25. this.html = this.dom_html
  26. this.compileTemplate()
  27. }else{ // else get it from ajax
  28. this.getMenuBlockHtml()
  29. }
  30. }
  31. },
  32. methods: {
  33. compileTemplate(){
  34. this.template = Vue.compile(this.html)
  35. },
  36. getMenuBlockHtml(){
  37. MA.get('materio_decoupled/ajax/getheadermenu')
  38. .then(({data}) => {
  39. // console.log('HeaderMenu getMenuBlockHtml data', data);
  40. this.html = data.rendered // record the html src into data
  41. })
  42. .catch(( error ) => {
  43. console.warn('Issue with getMenuBlockHtml', error)
  44. })
  45. },
  46. onclick (event) {
  47. // console.log("Clicked on header menu link", event);
  48. const href = event.target.getAttribute('href')
  49. this.$router.push(href)
  50. }
  51. },
  52. render(h) {
  53. // console.log('headerMenu render');
  54. if(!this.template){
  55. return h('span', 'Loading ...')
  56. }else{
  57. return this.template.render.call(this)
  58. }
  59. },
  60. watch: {
  61. html(n, o) {
  62. // console.log('header_menu html changed', o, n)
  63. this.compileTemplate()
  64. },
  65. isloggedin(n, o) {
  66. console.log("HeaderMenu isloggedin changed", o, n)
  67. this.getMenuBlockHtml()
  68. }
  69. }
  70. }
  71. </script>
  72. <style lang="scss" scoped>
  73. </style>