Answer the question
In order to leave comments, you need to log in
How to get data from a function (composition API)?
I decided to try the new composition API, there are 2 functions, both in different files, one of them is for a separate component (function 1), the other, so to speak, is global (function 2). A string from the input is passed from the component to function 1:
<input type="text" v-model="text" class="input" id="input-text">
, further in function 1 it is divided into an arrayexport function toCode(){
let text = ref("");
let array = ref([]);
let obj = reactive(scanArrays())
watch(text, () => {
array = text.value.split("");
obj = scanArrays(array, deciphering, cipher)
console.log(obj)//тут выводится все как надо
})
return{
text,
...obj
}
}
and passed to function 2:export function scanArrays(arr, decip, cip){
let err = ref({show:false, element:""});
let result = ref("");
const func = () => {
result.value = "";
err.value.show = false
arr.forEach(el => {
if(!decip.includes(el)){
err.value.show = true
err.value.element = `" ${el} "`;
return
}
let letterInd = decip.indexOf(el);
result.value += cip[letterInd] + " ";
});
}
if(arr) func()
return{
func,
result,
err
}
}
, but the component receives an unmodified objectsetup(){
return{
...toCode(),
}
}
, although function 1 outputs to the console exactly what I expect as a result. Please tell me what is wrong here.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question