HeaderMenu.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. // ...mapActions({
  34. // openCloseHamMenu: 'Common/openCloseHamMenu'
  35. // }),
  36. compileTemplate(){
  37. this.template = Vue.compile(this.html)
  38. },
  39. getMenuBlockHtml(){
  40. MA.get('materio_decoupled/ajax/getheadermenu')
  41. .then(({data}) => {
  42. // console.log('HeaderMenu getMenuBlockHtml data', data)
  43. this.html = data.rendered // record the html src into data
  44. })
  45. .catch((error) => {
  46. console.warn('Issue with getMenuBlockHtml', error)
  47. })
  48. },
  49. onclick (event) {
  50. // console.log("Clicked on header menu link", event)
  51. const href = event.target.getAttribute('href')
  52. // this.openCloseHamMenu(false)
  53. // this.$router.push({name:'base', query:{
  54. // keys:this.typed,
  55. // // terms:this.autocomplete.join(','),
  56. // terms: JSON.stringify(this.autocomplete),
  57. // filters:filters.join(',')
  58. // }})
  59. this.$router.push({path: href, query: {}})
  60. }
  61. },
  62. render(h) {
  63. // console.log('headerMenu render')
  64. if (!this.template) {
  65. return h('span', $t('default.Loading…'))
  66. } else {
  67. return this.template.render.call(this)
  68. }
  69. },
  70. watch: {
  71. html(n, o) {
  72. // console.log('header_menu html changed', o, n)
  73. this.compileTemplate()
  74. },
  75. isloggedin(n, o) {
  76. console.log("HeaderMenu isloggedin changed", o, n)
  77. this.getMenuBlockHtml()
  78. }
  79. }
  80. }
  81. </script>
  82. <style lang="scss" scoped>
  83. </style>