Title.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <h1 v-if="false"><slot> </slot></h1>
  3. </template>
  4. <script>
  5. export default {
  6. name: 'v-title',
  7. data() {
  8. return {
  9. }
  10. },
  11. mounted () {
  12. this.updateTitle()
  13. },
  14. beforeUpdate () {
  15. this.updateTitle()
  16. },
  17. activated() {
  18. this.updateTitle()
  19. },
  20. methods: {
  21. updateTitle () {
  22. let slots = this.$slots.default;
  23. if (typeof slots === 'undefined' || slots.length < 1 || typeof slots[0].text !== 'string') {
  24. return;
  25. }
  26. let {text} = slots[0];
  27. let {title} = document;
  28. if (text !== title) this.setTile(text);
  29. },
  30. setTile(title) {
  31. document.title = title;
  32. let mobile = navigator.userAgent.toLowerCase();
  33. if (/iphone|ipad|ipod/.test(mobile)) {
  34. let iframe = document.createElement('iframe');
  35. iframe.style.display = 'none';
  36. let iframeCallback = function () {
  37. setTimeout(function () {
  38. iframe.removeEventListener('load', iframeCallback);
  39. document.body.removeChild(iframe)
  40. }, 0)
  41. };
  42. iframe.addEventListener('load', iframeCallback);
  43. document.body.appendChild(iframe)
  44. }
  45. }
  46. }
  47. }
  48. </script>