Advertisement
tomuwhu

mértékegység átváltó

Oct 22nd, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// https://9c1h7.csb.app/
  2. <template>
  3.   <div id="app">
  4.     <span
  5.       :class="key===mode?'oa':'ob'"
  6.       :key="key"
  7.       v-for="(elem, key) in c"
  8.       @click="mode=key, a=0"> {{elem.kii}} </span><hr>
  9.     <select v-model="mode">
  10.       <option
  11.           :key = "key"
  12.           v-for="(elem, key) in c"
  13.           :value="key">{{elem.kii}}</option>
  14.     </select> átváltó<br><br><br>
  15.     <input
  16.       @click="$event.target.select()"
  17.       placeholder="lóerő"
  18.       v-model.number="a"> {{c[mode].me1}} <br>
  19.     <input
  20.       @click="$event.target.select()"
  21.       placeholder="kw"
  22.       v-model.number="a2"> {{c[mode].me2}}
  23.   </div>
  24. </template>
  25.  
  26. <script>
  27. export default {
  28.   data() {
  29.     return {
  30.       mode: 0,
  31.       a: 0,
  32.       c: [
  33.         { p:0, sz: 1.34, me1: 'kw', me2: 'Le', kii: 'Teljesítmény (KW - Le)' },
  34.         { p:32, sz: 9/5, me1: '℃', me2: '℉', kii: 'Hőmérséklet (℃ - ℉)' },
  35.         { p:0, sz: 3.6, me1: 'm/s', me2: 'km/h', kii: 'Sebesség (km/h - m/s)' },
  36.       ]
  37.     }
  38.   },
  39.   computed: {
  40.     a2: {
  41.       get() {
  42.         return Number( (this.c[this.mode].p+this.a*this.c[this.mode].sz).toFixed(2) )
  43.       },
  44.       set(x) {
  45.         this.a=Number( ( (x-this.c[this.mode].p)/this.c[this.mode].sz).toFixed(3) )
  46.       }
  47.     }
  48.   }
  49. };
  50. </script>
  51.  
  52. <style>
  53. .oa {
  54.   background: rgb(70, 55, 77);
  55.   color: aliceblue ;
  56. }
  57. .ob {
  58.   background: rgb(202, 186, 210);
  59. }
  60. span {
  61.   cursor:pointer ;
  62.   background: #ecf;
  63.   margin:10px;
  64.   padding: 4px;
  65.   border-radius: 6px;
  66.   box-shadow: 1px 1px 3px black;
  67. }
  68. body, input, select {
  69.   font-size: 24px;
  70. }
  71. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement