index.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <view class="main">
  3. <code-elf-guide v-if="guidePages"></code-elf-guide>
  4. </view>
  5. </template>
  6. <script>
  7. import codeElfGuide from '@/components/code-elf-guide/code-elf-guide.vue'
  8. export default {
  9. components: {
  10. codeElfGuide
  11. },
  12. data() {
  13. return {
  14. guidePages: true
  15. }
  16. },
  17. onLoad() {
  18. this.loadExecution()
  19. },
  20. methods: {
  21. loadExecution: function() {
  22. /**
  23. * 获取本地存储中launchFlag的值
  24. * 若存在,说明不是首次启动,直接进入首页;
  25. * 若不存在,说明是首次启动,进入引导页;
  26. */
  27. try {
  28. // 获取本地存储中launchFlag标识
  29. const value = uni.getStorageSync('launchFlag');
  30. if (value) {
  31. // launchFlag=true直接跳转到首页
  32. uni.switchTab({
  33. url: '/pages/home/home'
  34. });
  35. } else {
  36. // launchFlag!=true显示引导页
  37. this.guidePages = true
  38. }
  39. } catch (e) {
  40. // error
  41. uni.setStorage({
  42. key: 'launchFlag',
  43. data: true,
  44. success: function() {
  45. console.log('error时存储launchFlag');
  46. }
  47. });
  48. this.guidePages = true
  49. }
  50. }
  51. }
  52. }
  53. </script>
  54. <style>
  55. page,
  56. .main {
  57. width: 100%;
  58. height: 100%;
  59. }
  60. </style>