In a vue app, I want to use a variable defined from a param, passed through the URL, in the template section. But when I try to use it, I get an undefined error when used in the template (though it is used in the script section and shows as defined).
I thought returning the variable would let me use it in the template section, but I get a duplicate key warning.
<template>
<div>
<router-link
:to="{ path: `/${m}`}" //this shows as
undefined
>Link</router-link
>
</div>
</template>
<script>
export default {
name: "template",
props: ["m"],
setup() {
const route = useRoute();
const m = ref(route.params.m);
console.log(m.value) //this works
return {
m //This shows as a duplicate key
};
},
};
</script>
CodePudding user response:
Change variable name m
in setup().