|
| 1 | +<template> |
| 2 | +<b-container class="pt-4"> |
| 3 | + <b-form @submit="onSubmit"> |
| 4 | + <b-form-group label="Fill in the following fields to calculate derivative" class="pt-2"> |
| 5 | + <b-input-group prepend="function"> |
| 6 | + <b-input |
| 7 | + id="integrating-function" |
| 8 | + v-model="differentiableFunction" |
| 9 | + required |
| 10 | + placeholder="a function to take derivative" |
| 11 | + /> |
| 12 | + </b-input-group> |
| 13 | + <b-input-group prepend="variable: " class="pt-1"> |
| 14 | + <b-input |
| 15 | + v-model="independentVariable" |
| 16 | + required |
| 17 | + placeholder="an independent variable" |
| 18 | + /> |
| 19 | + </b-input-group> |
| 20 | + <b-input-group prepend="order" class="pt-1"> |
| 21 | + <b-input |
| 22 | + v-model="order" |
| 23 | + placeholder="default is 1" |
| 24 | + type="number" |
| 25 | + /> |
| 26 | + </b-input-group> |
| 27 | + </b-form-group> |
| 28 | + |
| 29 | + <b-row align-h="center"> |
| 30 | + <b-col md="6" sm="12"> |
| 31 | + <b-button block type="submit" variant="primary"> |
| 32 | + Submit |
| 33 | + </b-button> |
| 34 | + </b-col> |
| 35 | + </b-row> |
| 36 | + </b-form> |
| 37 | + |
| 38 | + <b-row align-h="center" class="pt-4" v-if="fetching"> |
| 39 | + <b-spinner /> |
| 40 | + </b-row> |
| 41 | + |
| 42 | + <AnswerImage v-else-if="answer" :answer="answer" /> |
| 43 | + |
| 44 | + <b-row align-h="center" class="p-2" v-else-if="error"> |
| 45 | + Something went wrong... |
| 46 | + </b-row> |
| 47 | +</b-container> |
| 48 | +</template> |
| 49 | + |
| 50 | +<script> |
| 51 | +import AnswerImage from '@/components/common/AnswerImage' |
| 52 | +import {makeSimpleRequest} from '@/utils' |
| 53 | +
|
| 54 | +export default { |
| 55 | + components: {AnswerImage}, |
| 56 | + methods: { |
| 57 | + async onSubmit (event) { |
| 58 | + event.preventDefault() |
| 59 | + const orderNumber = this.order.length > 0 ? Number(this.order) : 1 |
| 60 | + const differentialOperator = (Number.isInteger(orderNumber) && orderNumber >= 2) |
| 61 | + ? `d^${orderNumber}/d${this.independentVariable}^${orderNumber}` |
| 62 | + : `d/d${this.independentVariable}` |
| 63 | + const requestString = `${differentialOperator} ${this.differentiableFunction}` |
| 64 | + this.fetching = true |
| 65 | + try { |
| 66 | + const response = await makeSimpleRequest(requestString) |
| 67 | + this.answer = response |
| 68 | + this.error = Boolean(response) |
| 69 | + } catch (error) { |
| 70 | + console.log(error) |
| 71 | + this.error = true |
| 72 | + } |
| 73 | + this.fetching = false |
| 74 | + } |
| 75 | + }, |
| 76 | + data () { |
| 77 | + return { |
| 78 | + differentiableFunction: '', |
| 79 | + independentVariable: 'x', |
| 80 | + order: '', |
| 81 | + answer: null, |
| 82 | + fetching: false, |
| 83 | + error: false |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | +</script> |
| 88 | + |
| 89 | +<style scoped> |
| 90 | +</style> |
0 commit comments