2019-06-03 13:06:44 +02:00
|
|
|
<script>
|
|
|
|
|
|
|
|
import Vue from 'vue'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props: ['html'], // get the html from parent with props
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
template: null // compiled template from html used in render
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeMount() {
|
2019-06-04 22:38:44 +02:00
|
|
|
// console.log('Home beforeMount');
|
2019-06-03 13:06:44 +02:00
|
|
|
// compile the html src (coming from parent with props or from ajax call)
|
2019-06-04 22:38:44 +02:00
|
|
|
if(this.html){
|
|
|
|
// console.log('html', this.html);
|
|
|
|
this.template = Vue.compile(this.html)
|
2019-06-03 13:06:44 +02:00
|
|
|
this.$options.staticRenderFns = []
|
|
|
|
this._staticTrees = []
|
|
|
|
this.template.staticRenderFns.map(fn => (this.$options.staticRenderFns.push(fn)))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
render(h) {
|
|
|
|
if(!this.template){
|
|
|
|
return h('span', 'Loading ...')
|
|
|
|
}else{
|
|
|
|
return this.template.render.call(this)
|
|
|
|
}
|
2020-12-26 22:33:25 +01:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onClickLink(e){
|
2020-12-27 11:09:03 +01:00
|
|
|
console.log("onClickLink", e, this.$router, this.$route);
|
2020-12-26 22:33:25 +01:00
|
|
|
let path = null;
|
2020-12-27 11:09:03 +01:00
|
|
|
// find existing router route compared with link href
|
|
|
|
for (var i = 0; i < this.$router.options.routes.length; i++) {
|
|
|
|
if (this.$router.options.routes[i].path == e.originalTarget.pathname) {
|
|
|
|
if (e.originalTarget.pathname !== this.$route.path) {
|
|
|
|
path = e.originalTarget.pathname
|
|
|
|
}
|
|
|
|
break;
|
2020-12-26 22:33:25 +01:00
|
|
|
}
|
2020-12-27 11:09:03 +01:00
|
|
|
}
|
2020-12-26 22:33:25 +01:00
|
|
|
|
|
|
|
if (path) {
|
|
|
|
this.$router.push({
|
|
|
|
path: path
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-06-03 13:06:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
</style>
|