Advertisement
justinzi

v

Jul 19th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <div class="py-4">
  3.     <v-card class="rounded-card mb-4" v-for="(item, index) in cardInfo" :key="index">
  4.       <v-card-title>
  5.         <v-icon color="secondary" left>{{item.icon}}</v-icon>
  6.         <span class="title font-weight-light">{{item.name}}</span>
  7.       </v-card-title>
  8.       <v-divider></v-divider>
  9.       <v-list v-for="(item, index) in item.content" :key="index">
  10.         <v-list-tile>
  11.           <v-list-tile-content>
  12.             <v-list-tile-title>{{item.content}}</v-list-tile-title>
  13.             <v-list-tile-sub-title>{{item.name}}</v-list-tile-sub-title>
  14.           </v-list-tile-content>
  15.         </v-list-tile>
  16.       </v-list>
  17.     </v-card>
  18.   </div>
  19. </template>
  20.  
  21. <script>
  22. export default {
  23.   data() {
  24.     return {
  25.       mouseEvent: "determining...",
  26.       motionEvent: "determining...",
  27.       orientEvent: "determining...",
  28.       absolute: "",
  29.       alpha: 0,
  30.       beta: 0,
  31.       gamma: 0,
  32.       accelX: 0,
  33.       accelY: 0,
  34.       accelZ: 0,
  35.       eventAlpha: "determining...",
  36.       eventBeta: "determining..."
  37.     };
  38.   },
  39.   created() {
  40.     window.addEventListener("devicemotion", this.accelMove);
  41.     window.addEventListener("deviceorientation", this.gyroMove);
  42.   },
  43.   destroyed() {
  44.     window.removeEventListener("devicemotion", this.accelMove);
  45.     window.removeEventListener("deviceorientation", this.gyroMove);
  46.   },
  47.   computed: {
  48.     gyroInfo: function() {
  49.       return [
  50.         { name: "alpha", content: this.alpha.toFixed(4) },
  51.         { name: "beta", content: this.beta.toFixed(4) },
  52.         { name: "gamma", content: this.gamma.toFixed(4) }
  53.       ];
  54.     },
  55.     accelInfo: function() {
  56.       return [
  57.         { name: "x", content: this.accelX.toFixed(4) },
  58.         { name: "y", content: this.accelY.toFixed(4) },
  59.         { name: "z", content: this.accelZ.toFixed(4) }
  60.       ];
  61.     },
  62.     cardInfo: function() {
  63.       return [
  64.         { name: "Gyroscope", icon: "360", content: this.gyroInfo },
  65.         { name: "Accelerometer", icon: "forward", content: this.accelInfo }
  66.       ];
  67.     }
  68.   },
  69.   methods: {
  70.     accelMove(event) {
  71.       this.accelX = event.acceleration.x;
  72.       this.accelY = event.acceleration.y;
  73.       this.accelZ = event.acceleration.z;
  74.     },
  75.     gyroMove(event) {
  76.       this.absolute = event.absolute;
  77.       this.alpha = event.alpha;
  78.       this.beta = event.beta;
  79.       this.gamma = event.gamma;
  80.     }
  81.   }
  82. };
  83. </script>
  84.  
  85. <style>
  86. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement