MainContent.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template lang="html">
  2. <div :id="id">
  3. <router-view name="home" :html="home_template_src"></router-view>
  4. <router-view name="base"></router-view>
  5. </div>
  6. </template>
  7. <script>
  8. import { mapState, mapActions } from 'vuex'
  9. import { MA } from 'vuejs/api/ma-axios'
  10. import router from 'vuejs/route'
  11. export default {
  12. router,
  13. props:['id','html', 'isfront'],
  14. data() {
  15. return {
  16. home_template_src: null
  17. }
  18. },
  19. beforeMount() {
  20. // console.log('MainContent beforeMount this.html', this.html);
  21. if(!this.home_template_src){
  22. // console.log('no home_template_src');
  23. if(this.html && this.isfront){ // if html prop is available and we are landing on home then record it has data
  24. this.home_template_src = this.html
  25. }else{ // else get it from ajax (e.g. if we didn't load the page from home)
  26. this.getHomeHtml()
  27. }
  28. }
  29. },
  30. methods: {
  31. getHomeHtml(){
  32. MA.get('materio_home/ajax/gethome')
  33. .then(({data}) => {
  34. // console.log('Home getHomeHtml data', data);
  35. this.home_template_src = data.rendered // record the html src into data
  36. })
  37. .catch(( error ) => {
  38. console.warn('Issue with getHomeHtml', error)
  39. })
  40. }
  41. }
  42. }
  43. </script>
  44. <style lang="scss" scoped>
  45. </style>