materio-d9/web/themes/custom/materiotheme/vuejs/components/Content/HeaderMenu.vue

91 lines
2.2 KiB
Vue
Raw Normal View History

<script>
import Vue from 'vue'
import { mapState, mapActions } from 'vuex'
import MA from 'vuejs/api/ma-axios'
import router from 'vuejs/route'
export default {
router,
props:['id','dom_html'],
data() {
return {
html: null,
template: null
}
},
computed: {
...mapState({
isloggedin: state => state.User.isloggedin
})
},
beforeMount() {
// console.log("beforeMount header_menu", this.html)
if (!this.template) {
// console.log('no home_template')
if (this.dom_html) { // if html prop is available
this.html = this.dom_html
this.compileTemplate()
} else { // else get it from ajax
this.getMenuBlockHtml()
}
}
},
methods: {
// ...mapActions({
// openCloseHamMenu: 'Common/openCloseHamMenu'
// }),
compileTemplate(){
this.template = Vue.compile(this.html)
},
getMenuBlockHtml(){
MA.get('materio_decoupled/ajax/getheadermenu')
.then(({data}) => {
// console.log('HeaderMenu getMenuBlockHtml data', data)
this.html = data.rendered // record the html src into data
})
.catch((error) => {
console.warn('Issue with getMenuBlockHtml', error)
})
},
onclick (event) {
// console.log("Clicked on header menu link", event)
const href = event.target.getAttribute('href')
// this.openCloseHamMenu(false)
// this.$router.push({name:'base', query:{
// keys:this.typed,
// // terms:this.autocomplete.join(','),
// terms: JSON.stringify(this.autocomplete),
// filters:filters.join(',')
// }})
this.$router.push({path: href, query: {}})
}
},
render(h) {
// console.log('headerMenu render')
if (!this.template) {
2021-06-01 22:46:15 +02:00
return h('span', $t('default.Loading…'))
} else {
return this.template.render.call(this)
}
},
watch: {
html(n, o) {
// console.log('header_menu html changed', o, n)
this.compileTemplate()
},
isloggedin(n, o) {
console.log("HeaderMenu isloggedin changed", o, n)
this.getMenuBlockHtml()
}
}
}
</script>
<style lang="scss" scoped>
</style>