Where should I define a function in a SPA using the options API that will be called from an HTML href?
Check out this demo on Codepen where everything works fine:
However, when I try to implement it in my single-page application:
<template>
<div v-html="my_div" />
</template>
<script>
/* function MyFunction() {
alert();
}; */
const MyFunction = () => {
alert();
};
/* Just for explanation, because the data comes from the database
export default {
data() {
return {
my_div:'<a href="javascript:MyFunction(10)">link call function</a> ',
}
}
*/
}
</script>
When trying to call the function, I receive the following error:
Uncaught ReferenceError: MyFunction is not defined
It seems that the function is defined after the call. Any suggestions on how to solve this issue?