I am trying to get the current time with moment in vue 3 with composition api, create a function in my useComposition like so:
import moment from "moment"
export default function (){
//Funcion para obtener el tiempo actual, tiempo al crear o editar un registro
const horaActual = ()=> {
const hoy = moment()
console.log(hoy.toString())
}
return { ...toRefs(state), apartments, horaActual, resetFilters, paginateEntrusts }
}
then in my component EntrustForm.vue
import and use
<script>
import TextInput from "../../UI/Tenant/TextInput";
import useEntrust from "../../../composables/Tenant/EntrustRegistration/useEntrust"
export default {
name: "EntrustForm",
components: { SubmitButton, TextInput },
setup(){
const { entrusts, horaActual } = useEntrust();
return {
entrusts,
horaActual
}
},
}
</script>
Then in my input I would like to load this date, however when I try to call it it does not work for me, it throws me an error
it is in this input where I would like to load the date when opening my create view
<div class="col-span-6 sm:col-span-3 lg:col-span-3">
<label for="fecha" class="block text-sm font-medium text-gray-700 dark:text-gray-200">Fecha recepción</label>
<text-input name="fecha" :model="fecha" @input="$emit('update:fecha', $event.target.value)" autocomplete="family-name" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border border-gray-300 rounded-md" />
<p>{{horaActual}}</p>
</div>
in my main.js I have the import like this:
import moment from 'moment'
moment.locale('es')
createApp(App)
.use(store)
.use(storeTenant)
.use(router)
.use(moment)
.mount('#app')
My question is how can I load it and solve this problem?
The errors are the following:
horaActual
it is a function, but when you print it you are not executing it.horaActual
does not return anything, but does aconsole.log
Solution:
Modify the function
horaActual
so that it returns something:Print the result of running
horaActual