Home.vue 1.4 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, this.$route);
  31. let path = null;
  32. // find existing router route compared with link href
  33. for (var i = 0; i < this.$router.options.routes.length; i++) {
  34. if (this.$router.options.routes[i].path == e.originalTarget.pathname) {
  35. if (e.originalTarget.pathname !== this.$route.path) {
  36. path = e.originalTarget.pathname
  37. }
  38. break;
  39. }
  40. }
  41. if (path) {
  42. this.$router.push({
  43. path: path
  44. })
  45. }
  46. }
  47. }
  48. }
  49. </script>
  50. <style lang="scss" scoped>
  51. </style>