Home.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <script>
  2. import Vue from 'vue'
  3. export default {
  4. props: ['html'], // get the html from parent with props
  5. data() {
  6. return {
  7. template: null // compiled template from html used in render
  8. }
  9. },
  10. beforeMount() {
  11. // console.log('Home beforeMount');
  12. // compile the html src (coming from parent with props or from ajax call)
  13. if(this.html){
  14. // console.log('html', this.html);
  15. this.template = Vue.compile(this.html)
  16. this.$options.staticRenderFns = []
  17. this._staticTrees = []
  18. this.template.staticRenderFns.map(fn => (this.$options.staticRenderFns.push(fn)))
  19. }
  20. },
  21. render(h) {
  22. if(!this.template){
  23. return h('span', 'Loading ...')
  24. }else{
  25. return this.template.render.call(this)
  26. }
  27. },
  28. methods: {
  29. onClickLink(e){
  30. console.log("onClickLink", e, this.$router);
  31. let path = null;
  32. this.$router.options.routes.forEach(route => {
  33. // console.log('route.path', route.path);
  34. if (route.path == e.originalTarget.pathname) {
  35. path = e.originalTarget.pathname
  36. // TODO: check if path is current
  37. // TODO: as we can't break forEach is not the good method here
  38. }
  39. }, this)
  40. if (path) {
  41. this.$router.push({
  42. path: path
  43. })
  44. }
  45. }
  46. }
  47. }
  48. </script>
  49. <style lang="scss" scoped>
  50. </style>