Presently, I am utilizing a component named countdowntimer.vue, specifically designed as a countdown timer for an online examination platform. My goal is to implement an onbeforeunload
event on the window object while ensuring that the timer automatically submits upon completion without being disrupted by the window event itself. Despite my attempts to integrate this code within the vuejs component, it fails to respond as desired; either hindering the submission process with interruptions or failing to function altogether, allowing any event to navigate away from the page without constraint.
Below is the code snippet depicting the countdown timer:
<template>
<div>
<div v-if="finished" v-text="expiredText"></div>
<div v-else>
<span>{{ remaining.minutes }} Minutes, </span>
<span>{{ remaining.seconds }} Seconds</span>
left...
</div>
</div>
</template>
....
Despite various trials of setting the method as a computed property and employing different if statements as watchers, the method does not yield the expected outcomes as previously mentioned.
The blade template in which the code is implemented is presented below:
@extends('layouts.app')
@section('content')
...
</div>
@endsection
.....
Upon observation, there appears to be a script tag located outside of the @endsection
block. It has been discerned that this placement fails to establish a connection with elements from the blade template. Attempts were made to access the form object similarly done in the vue component. However, this resulted in a null or undefined response - rendering it impossible to attach an event listener. Interestingly, executing the same logic within the browser console produced the anticipated results. The assigned onsubmit=""
event intended for the form failed to reach the underlying script tags, leading to an unaltered value in the submitForm
variable. Moreover, manually clicking the submit button succeeded in triggering the function clicked()
. Under these circumstances, confusion ensues regarding the feasibility of achieving the desired outcome solely through vue. Additionally, the nonfunctional nature of the onsubmit=""
event raises uncertainties. Moving the script tags inside the @section
could potentially prompt errors from vue. Hence, any recommendations or insights on resolving these issues would be greatly appreciated.