get-launch-options-sync.uvue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <page-head title="getLaunchOptionsSync"></page-head>
  3. <view class="uni-padding-wrap">
  4. <button @click="getLaunchOptionsSync">getLaunchOptionsSync</button>
  5. <view class="uni-common-mt">
  6. <text>应用本次启动路径:</text>
  7. <text style="margin-top: 5px">{{ launchOptionsPath }}</text>
  8. </view>
  9. <view class="uni-common-mt">
  10. <text>应用本次启动:</text>
  11. <text style="margin-top: 5px">{{ launchOptionsString }}</text>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. data() {
  18. return {
  19. checked: false,
  20. homePagePath: 'pages/tabBar/component',
  21. launchOptionsPath: '',
  22. launchOptionsString: '',
  23. testResult: false
  24. }
  25. },
  26. onReady() {
  27. this.compareOnLaunchRes()
  28. },
  29. methods: {
  30. compareOnLaunchRes() {
  31. const launchOptions = uni.getLaunchOptionsSync();
  32. this.launchOptionsString = JSON.stringify(launchOptions, null, 2)
  33. const app = getApp()
  34. const appOnLaunch = app.globalData.launchOptions
  35. const isPathSame = launchOptions.path == appOnLaunch.path
  36. const isAppSchemeSame = launchOptions.appScheme == appOnLaunch.appScheme
  37. const isAppLinkSame = launchOptions.appLink == appOnLaunch.appLink
  38. this.testResult = isPathSame && isAppSchemeSame && isAppLinkSame
  39. },
  40. getLaunchOptionsSync() {
  41. const launchOptions = uni.getLaunchOptionsSync()
  42. this.launchOptionsPath = launchOptions.path
  43. if (launchOptions.path == this.homePagePath) {
  44. this.checked = true
  45. }
  46. },
  47. },
  48. }
  49. </script>