LanguageSwitcher.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <script>
  2. import Vue from 'vue'
  3. import router from 'vuejs/route'
  4. export default {
  5. name: "LanguageSwitcher",
  6. router,
  7. props:['id','dom_html'],
  8. data() {
  9. return {
  10. html: null,
  11. template: null
  12. }
  13. },
  14. beforeMount() {
  15. console.log("beforeMount languageSwitcher", this.dom_html)
  16. if (!this.template) {
  17. console.log('no languageswitcher template')
  18. if (this.dom_html) { // if html prop is available
  19. this.html = this.dom_html
  20. this.compileTemplate()
  21. }
  22. }
  23. },
  24. methods: {
  25. compileTemplate(){
  26. console.log("languageSwitcher compileTemplate html", this.html)
  27. this.template = Vue.compile(this.html)
  28. // https://github.com/vuejs/vue/issues/9911
  29. this.$options.staticRenderFns = [];
  30. this._staticTrees = [];
  31. this.template.staticRenderFns.map(fn => (this.$options.staticRenderFns.push(fn)));
  32. console.log("languageSwitcher compileTemplate template", this.template)
  33. },
  34. onTapLanguageSwitcher (e) {
  35. console.log('onTapLanguageSwitcher', e)
  36. let tapped = e.target.parentNode.parentNode.querySelectorAll('.tapped')
  37. tapped.forEach((item, i) => {
  38. item.classList.remove('tapped')
  39. })
  40. e.target.parentNode.classList.add('tapped')
  41. }
  42. },
  43. render(h) {
  44. console.log('languageswitcher render')
  45. if (!this.template) {
  46. return h('span', $t('default.Loading…'))
  47. } else {
  48. return this.template.render.call(this)
  49. }
  50. }
  51. }
  52. </script>
  53. <style lang="scss" scoped>
  54. </style>